Update app.py
Browse files
app.py
CHANGED
|
@@ -117,18 +117,19 @@ def retrosynthesis(reactant, prompt):
|
|
| 117 |
reactants.append(smiles)
|
| 118 |
reactant_images.append(Draw.MolToImage(mol, size=(600, 600)))
|
| 119 |
|
| 120 |
-
return reactants, reactant_images
|
| 121 |
|
| 122 |
def secondary_interface(smiles, atom1_idx, atom2_idx, operation):
|
| 123 |
try:
|
| 124 |
prompt, error = process_bond_operation(smiles, atom1_idx, atom2_idx, operation)
|
| 125 |
|
| 126 |
if prompt:
|
| 127 |
-
reactant_smiles, reactant_images = retrosynthesis(smiles, prompt)
|
| 128 |
output_components = [gr.update(value=prompt, visible=True)] # prompt_output
|
| 129 |
|
| 130 |
# Add the reactant SMILES and images
|
| 131 |
for i in range(len(reactant_smiles)):
|
|
|
|
| 132 |
output_components.append(gr.update(value=reactant_smiles[i], visible=True))
|
| 133 |
output_components.append(gr.update(value=reactant_images[i], visible=True))
|
| 134 |
|
|
@@ -136,15 +137,16 @@ def secondary_interface(smiles, atom1_idx, atom2_idx, operation):
|
|
| 136 |
for j in range(len(reactant_smiles), 10):
|
| 137 |
output_components.append(gr.update(visible=False))
|
| 138 |
output_components.append(gr.update(visible=False))
|
|
|
|
| 139 |
|
| 140 |
output_components.append(gr.update(visible=False)) # error_output
|
| 141 |
return output_components
|
| 142 |
|
| 143 |
else:
|
| 144 |
-
return [gr.update(visible=False)] *
|
| 145 |
|
| 146 |
except Exception as e:
|
| 147 |
-
return [gr.update(visible=False)] *
|
| 148 |
|
| 149 |
def clear_interface():
|
| 150 |
return (
|
|
@@ -155,7 +157,7 @@ def clear_interface():
|
|
| 155 |
gr.update(visible=False, value=None), # error_output
|
| 156 |
gr.update(value=None, visible=False), # prompt_output
|
| 157 |
) + ( # Reactant SMILES and Images
|
| 158 |
-
tuple(gr.update(value=None, visible=False) for _ in range(
|
| 159 |
)
|
| 160 |
|
| 161 |
# 示例数据
|
|
@@ -190,6 +192,7 @@ with gr.Blocks() as interface:
|
|
| 190 |
|
| 191 |
result_row = []
|
| 192 |
for i in range(10):
|
|
|
|
| 193 |
result_row.append(gr.Textbox(label=f"Reactant {i+1} SMILES", interactive=False, visible=False))
|
| 194 |
result_row.append(gr.Image(label=f"Reactant {i+1} Image", visible=False))
|
| 195 |
|
|
|
|
| 117 |
reactants.append(smiles)
|
| 118 |
reactant_images.append(Draw.MolToImage(mol, size=(600, 600)))
|
| 119 |
|
| 120 |
+
return reactseq_list, reactants, reactant_images
|
| 121 |
|
| 122 |
def secondary_interface(smiles, atom1_idx, atom2_idx, operation):
|
| 123 |
try:
|
| 124 |
prompt, error = process_bond_operation(smiles, atom1_idx, atom2_idx, operation)
|
| 125 |
|
| 126 |
if prompt:
|
| 127 |
+
reactseq_list, reactant_smiles, reactant_images = retrosynthesis(smiles, prompt)
|
| 128 |
output_components = [gr.update(value=prompt, visible=True)] # prompt_output
|
| 129 |
|
| 130 |
# Add the reactant SMILES and images
|
| 131 |
for i in range(len(reactant_smiles)):
|
| 132 |
+
output_components.append(gr.update(value=reactseq_list[i], visible=True))
|
| 133 |
output_components.append(gr.update(value=reactant_smiles[i], visible=True))
|
| 134 |
output_components.append(gr.update(value=reactant_images[i], visible=True))
|
| 135 |
|
|
|
|
| 137 |
for j in range(len(reactant_smiles), 10):
|
| 138 |
output_components.append(gr.update(visible=False))
|
| 139 |
output_components.append(gr.update(visible=False))
|
| 140 |
+
output_components.append(gr.update(visible=False))
|
| 141 |
|
| 142 |
output_components.append(gr.update(visible=False)) # error_output
|
| 143 |
return output_components
|
| 144 |
|
| 145 |
else:
|
| 146 |
+
return [gr.update(visible=False)] * 31 + [error] # Assuming 10 pairs of outputs + prompt_output + error_output
|
| 147 |
|
| 148 |
except Exception as e:
|
| 149 |
+
return [gr.update(visible=False)] * 31 + [gr.update(visible=True, value=str(e))]
|
| 150 |
|
| 151 |
def clear_interface():
|
| 152 |
return (
|
|
|
|
| 157 |
gr.update(visible=False, value=None), # error_output
|
| 158 |
gr.update(value=None, visible=False), # prompt_output
|
| 159 |
) + ( # Reactant SMILES and Images
|
| 160 |
+
tuple(gr.update(value=None, visible=False) for _ in range(30))
|
| 161 |
)
|
| 162 |
|
| 163 |
# 示例数据
|
|
|
|
| 192 |
|
| 193 |
result_row = []
|
| 194 |
for i in range(10):
|
| 195 |
+
result_row.append(gr.Textbox(label=f"Reactseq {i+1} ", interactive=False, visible=False))
|
| 196 |
result_row.append(gr.Textbox(label=f"Reactant {i+1} SMILES", interactive=False, visible=False))
|
| 197 |
result_row.append(gr.Image(label=f"Reactant {i+1} Image", visible=False))
|
| 198 |
|