Oopstom commited on
Commit
e36a5ab
1 Parent(s): 081f4b5

update visible state

Browse files
Files changed (3) hide show
  1. app.py +12 -24
  2. tmp_data/src.txt +1 -1
  3. tmp_data/tgt.txt +10 -10
app.py CHANGED
@@ -3,15 +3,6 @@ import gradio as gr
3
  from rdkit import Chem
4
  from rdkit.Chem import Draw
5
  import os
6
- import spaces
7
- import torch
8
- try:
9
- print(f"Is CUDA available: {torch.cuda.is_available()}")
10
- # True
11
- print(f"CUDA device: {torch.cuda.get_device_name(torch.cuda.current_device())}")
12
- # Tesla T4
13
- except:
14
- print("No GPU found!")
15
 
16
 
17
  def remove_atom_mapping_and_isotopes(smiles):
@@ -129,7 +120,7 @@ def retrosynthesis(reactant, prompt):
129
 
130
  return reactseq_list, reactants, reactant_images
131
 
132
- prompt_output = gr.Textbox(label="Prompt", interactive=False, visible=True) # 确保visible=True
133
 
134
  def secondary_interface(smiles, atom1_idx, atom2_idx, operation, progress=gr.Progress()):
135
  try:
@@ -137,19 +128,17 @@ def secondary_interface(smiles, atom1_idx, atom2_idx, operation, progress=gr.Pro
137
 
138
  if prompt:
139
  reactseq_list, reactant_smiles, reactant_images = retrosynthesis(smiles, prompt)
140
- output_components = [gr.update(value=prompt)] # prompt_output
141
 
142
- # Add the reactant SMILES and images
143
  for i in range(len(reactant_smiles)):
144
- output_components.append(gr.update(value=reactseq_list[i], visible=True))
145
- output_components.append(gr.update(value=reactant_smiles[i], visible=True))
146
- output_components.append(gr.update(value=reactant_images[i], visible=True))
147
-
148
- # Fill remaining hidden outputs
149
- for j in range(len(reactant_smiles), 10):
150
- output_components.append(gr.update(visible=False))
151
- output_components.append(gr.update(visible=False))
152
- output_components.append(gr.update(visible=False))
153
 
154
  output_components.append(gr.update(visible=False)) # error_output
155
  return output_components
@@ -161,6 +150,7 @@ def secondary_interface(smiles, atom1_idx, atom2_idx, operation, progress=gr.Pro
161
  return [gr.update(visible=False)] * 31 + [gr.update(visible=True, value=str(e))]
162
 
163
 
 
164
  def clear_interface():
165
  return (
166
  gr.update(value=None), # img_output
@@ -186,7 +176,7 @@ with gr.Blocks() as interface:
186
  gr.Markdown("The operation can be one of the following: break this bond, change this bond to single bond, change this bond to double bond, change this bond to triple bond.")
187
  gr.Markdown("The molecule image and SMILES with atom mapping will be displayed.")
188
  gr.Markdown("After you input the operation, the prompt will be displayed.")
189
- gr.Markdown("The reactants SMILES and images will be displayed after the retrosynthesis with **default** ranking.")
190
 
191
  smiles_input = gr.Textbox(placeholder="Please input your SMILES string", label="SMILES input")
192
  submit_smiles_button = gr.Button("Submit SMILES")
@@ -211,7 +201,6 @@ with gr.Blocks() as interface:
211
 
212
  error_output = gr.Textbox(label="Error Message", interactive=False, visible=False)
213
 
214
- # 添加清除按钮
215
  clear_button = gr.Button("Clear")
216
 
217
  submit_smiles_button.click(main_interface, inputs=[smiles_input], outputs=[img_output, smiles_output, secondary_inputs, secondary_inputs, error_output])
@@ -221,7 +210,6 @@ with gr.Blocks() as interface:
221
  outputs=[prompt_output] + result_row + [error_output]
222
  )
223
 
224
- # 清除按钮的事件处理
225
  clear_button.click(
226
  clear_interface,
227
  inputs=[],
 
3
  from rdkit import Chem
4
  from rdkit.Chem import Draw
5
  import os
 
 
 
 
 
 
 
 
 
6
 
7
 
8
  def remove_atom_mapping_and_isotopes(smiles):
 
120
 
121
  return reactseq_list, reactants, reactant_images
122
 
123
+ prompt_output = gr.Textbox(label="Prompt", interactive=False, visible=True)
124
 
125
  def secondary_interface(smiles, atom1_idx, atom2_idx, operation, progress=gr.Progress()):
126
  try:
 
128
 
129
  if prompt:
130
  reactseq_list, reactant_smiles, reactant_images = retrosynthesis(smiles, prompt)
131
+ output_components = [gr.update(value=prompt)]
132
 
 
133
  for i in range(len(reactant_smiles)):
134
+ if reactant_smiles[i] != "":
135
+ output_components.append(gr.update(value=reactseq_list[i], visible=True))
136
+ output_components.append(gr.update(value=reactant_smiles[i], visible=True))
137
+ output_components.append(gr.update(value=reactant_images[i], visible=True))
138
+ else:
139
+ output_components.append(gr.update(visible=False))
140
+ output_components.append(gr.update(visible=False))
141
+ output_components.append(gr.update(visible=False))
 
142
 
143
  output_components.append(gr.update(visible=False)) # error_output
144
  return output_components
 
150
  return [gr.update(visible=False)] * 31 + [gr.update(visible=True, value=str(e))]
151
 
152
 
153
+
154
  def clear_interface():
155
  return (
156
  gr.update(value=None), # img_output
 
176
  gr.Markdown("The operation can be one of the following: break this bond, change this bond to single bond, change this bond to double bond, change this bond to triple bond.")
177
  gr.Markdown("The molecule image and SMILES with atom mapping will be displayed.")
178
  gr.Markdown("After you input the operation, the prompt will be displayed.")
179
+ gr.Markdown("The reactants SMILES and images will be displayed after the retrosynthesis with **default** ranking, with the invalid ones deleted.")
180
 
181
  smiles_input = gr.Textbox(placeholder="Please input your SMILES string", label="SMILES input")
182
  submit_smiles_button = gr.Button("Submit SMILES")
 
201
 
202
  error_output = gr.Textbox(label="Error Message", interactive=False, visible=False)
203
 
 
204
  clear_button = gr.Button("Clear")
205
 
206
  submit_smiles_button.click(main_interface, inputs=[smiles_input], outputs=[img_output, smiles_output, secondary_inputs, secondary_inputs, error_output])
 
210
  outputs=[prompt_output] + result_row + [error_output]
211
  )
212
 
 
213
  clear_button.click(
214
  clear_interface,
215
  inputs=[],
tmp_data/src.txt CHANGED
@@ -1 +1 @@
1
- N # C C 1 = C C = C ( C ( C ( O ) C ! C 2 = C C = C ( F ) C = C 2 ) N 2 C = N C = N 2 ) C = C 1
 
1
+ C [ S i ] ( C ) ( ! C 1 = C C = C C = C 1 ) C 1 = C C = C C = C 1
tmp_data/tgt.txt CHANGED
@@ -1,10 +1,10 @@
1
- N # C C 1 = C C = C ( C ( C ( O ) C ! C 2 = C C = C ( F ) C = C 2 ) N 2 C = N C = N 2 ) C = C 1 < [ I : 1 ] > < O [ B : 1 ] O >
2
- N # C C 1 = C C = C ( C ( C ( O ) C ! C 2 = C C = C ( F ) C = C 2 ) N 2 C = N C = N 2 ) C = C 1 < [ B r : 1 ] > < O [ B : 1 ] O >
3
- N # C C 1 = C C = C ( C ( C ( O ) C ! C 2 = C C = C ( F ) C = C 2 ) N 2 C = N C = N 2 ) C = C 1 < [ I : 1 ] > < [ I : 1 ] >
4
- N # C C 1 = C C = C ( C ( C ( O ) C ! C 2 = C C = C ( F ) C = C 2 ) N 2 C = N C = N 2 ) C = C 1 < [ C l : 1 ] > < O [ B : 1 ] O >
5
- N # C C 1 = C C = C ( C ( C ( O ) C ! C 2 = C C = C ( F ) C = C 2 ) N 2 C = N C = N 2 ) C = C 1 < [ C l : 1 ] > < [ I : 1 ] >
6
- N # C C 1 = C C = C ( C ( C ( O ) C ! C 2 = C C = C ( F ) C = C 2 ) N 2 C = N C = N 2 ) C = C 1 < [ B r : 1 ] > < [ I : 1 ] >
7
- N # C C 1 = C C = C ( C ( C ( O ) C ! C 2 = C C = C ( F ) C = C 2 ) N 2 C = N C = N 2 ) C = C 1 < [ I : 1 ] > < [ M g + : 1 ] >
8
- N # C C 1 = C C = C ( C ( C ( O ) C ! C 2 = C C = C ( F ) C = C 2 ) N 2 C = N C = N 2 ) C = C 1 < [ I : 1 ] > < [ B r : 1 ] >
9
- N # C C 1 = C C = C ( C ( C ( O ) C ! C 2 = C C = C ( F ) C = C 2 ) N 2 C = N C = N 2 ) C = C 1 < [ B r : 1 ] > < O [ B : 1 ] C >
10
- N # C C 1 = C C = C ( C ( C ( O ) C ! C 2 = C C = C ( F ) C = C 2 ) N 2 C = N C = N 2 ) C = C 1 < [ B r : 1 ] > < O [ B : 1 ] O : 1 >
 
1
+ C [ S i ] ( C ) ( ! C 1 = C C = C C = C 1 ) C 1 = C C = C C = C 1 < [ C l : 1 ] > < - 1 >
2
+ C [ S i ] ( C ) ( ! C 1 = C C = C C = C 1 ) C 1 = C C = C C = C 1 < - 1 > < [ I : 1 ] >
3
+ C [ S i ] ( C ) ( ! C 1 = C C = C C = C 1 ) C 1 = C C = C C = C 1 < [ C l : 1 ] > < >
4
+ C [ S i ] ( C ) ( ! C 1 = C C = C C = C 1 ) C 1 = C C = C C = C 1 < - 1 > < [ B r : 1 ] >
5
+ C [ S i ] ( C ) ( ! C 1 = C C = C C = C 1 ) C 1 = C C = C C = C 1 < [ C l : 1 ] > < [ B r : 1 ] >
6
+ C [ S i ] ( C ) ( ! C 1 = C C = C C = C 1 ) C 1 = C C = C C = C 1 < [ C l : 1 ] > < [ I : 1 ] >
7
+ C [ S i ] ( C ) ( ! C 1 = C C = C C = C 1 ) C 1 = C C = C C = C 1 < [ B r : 1 ] > < - 1 >
8
+ C [ S i ] ( C ) ( ! C 1 = C C = C C = C 1 ) C 1 = C C = C C = C 1 < > < [ B r : 1 ] >
9
+ C [ S i ] ( C ) ( ! C 1 = C C = C C = C 1 ) C 1 = C C = C C = C 1 < [ C l : 1 ] > < - 1 , [ I : 1 ] >
10
+ C [ S i ] ( C ) ( ! C 1 = C C = C C = C 1 ) C 1 = C C = C C = C 1 < C [ S i : 1 ] ( C ) C > < >