Update app.py
Browse files
app.py
CHANGED
|
@@ -3,6 +3,7 @@ import gradio as gr
|
|
| 3 |
from rdkit import Chem
|
| 4 |
from rdkit.Chem import Draw
|
| 5 |
import os
|
|
|
|
| 6 |
|
| 7 |
def remove_atom_mapping_and_isotopes(smiles):
|
| 8 |
mol = Chem.MolFromSmiles(smiles)
|
|
@@ -119,13 +120,15 @@ def retrosynthesis(reactant, prompt):
|
|
| 119 |
|
| 120 |
return reactseq_list, reactants, reactant_images
|
| 121 |
|
| 122 |
-
|
|
|
|
|
|
|
| 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
|
| 129 |
|
| 130 |
# Add the reactant SMILES and images
|
| 131 |
for i in range(len(reactant_smiles)):
|
|
@@ -143,11 +146,12 @@ def secondary_interface(smiles, atom1_idx, atom2_idx, operation):
|
|
| 143 |
return output_components
|
| 144 |
|
| 145 |
else:
|
| 146 |
-
return [gr.update(visible=False)] * 31 + [error]
|
| 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 (
|
| 153 |
gr.update(value=None), # img_output
|
|
@@ -155,7 +159,7 @@ def clear_interface():
|
|
| 155 |
gr.update(visible=False), # secondary_inputs
|
| 156 |
gr.update(visible=False), # secondary_inputs
|
| 157 |
gr.update(visible=False, value=None), # error_output
|
| 158 |
-
gr.update(value=None, visible=
|
| 159 |
) + ( # Reactant SMILES and Images
|
| 160 |
tuple(gr.update(value=None, visible=False) for _ in range(30))
|
| 161 |
)
|
|
|
|
| 3 |
from rdkit import Chem
|
| 4 |
from rdkit.Chem import Draw
|
| 5 |
import os
|
| 6 |
+
import time
|
| 7 |
|
| 8 |
def remove_atom_mapping_and_isotopes(smiles):
|
| 9 |
mol = Chem.MolFromSmiles(smiles)
|
|
|
|
| 120 |
|
| 121 |
return reactseq_list, reactants, reactant_images
|
| 122 |
|
| 123 |
+
prompt_output = gr.Textbox(label="Prompt", interactive=False, visible=True) # 确保visible=True
|
| 124 |
+
|
| 125 |
+
def secondary_interface(smiles, atom1_idx, atom2_idx, operation, progress=gr.Progress()):
|
| 126 |
try:
|
| 127 |
prompt, error = process_bond_operation(smiles, atom1_idx, atom2_idx, operation)
|
| 128 |
|
| 129 |
if prompt:
|
| 130 |
reactseq_list, reactant_smiles, reactant_images = retrosynthesis(smiles, prompt)
|
| 131 |
+
output_components = [gr.update(value=prompt)] # prompt_output
|
| 132 |
|
| 133 |
# Add the reactant SMILES and images
|
| 134 |
for i in range(len(reactant_smiles)):
|
|
|
|
| 146 |
return output_components
|
| 147 |
|
| 148 |
else:
|
| 149 |
+
return [gr.update(visible=False)] * 31 + [error]
|
| 150 |
|
| 151 |
except Exception as e:
|
| 152 |
return [gr.update(visible=False)] * 31 + [gr.update(visible=True, value=str(e))]
|
| 153 |
|
| 154 |
+
|
| 155 |
def clear_interface():
|
| 156 |
return (
|
| 157 |
gr.update(value=None), # img_output
|
|
|
|
| 159 |
gr.update(visible=False), # secondary_inputs
|
| 160 |
gr.update(visible=False), # secondary_inputs
|
| 161 |
gr.update(visible=False, value=None), # error_output
|
| 162 |
+
gr.update(value=None, visible=True), # prompt_output
|
| 163 |
) + ( # Reactant SMILES and Images
|
| 164 |
tuple(gr.update(value=None, visible=False) for _ in range(30))
|
| 165 |
)
|