Spaces:
Runtime error
Runtime error
Upload app.py with huggingface_hub
Browse files
app.py
CHANGED
|
@@ -35,6 +35,17 @@ def mol_image(smiles: str):
|
|
| 35 |
return Draw.MolToImage(mol)
|
| 36 |
|
| 37 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 38 |
smiles_interface = gr.Interface(
|
| 39 |
fn=smiles_to_canonical,
|
| 40 |
inputs=gr.Textbox(label="SMILES"),
|
|
@@ -43,6 +54,15 @@ smiles_interface = gr.Interface(
|
|
| 43 |
description="Convert an input SMILES string to its canonical form.",
|
| 44 |
)
|
| 45 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 46 |
mw_interface = gr.Interface(
|
| 47 |
fn=molecular_weight,
|
| 48 |
inputs=gr.Textbox(label="SMILES"),
|
|
@@ -69,8 +89,9 @@ tpsa_interface = gr.Interface(
|
|
| 69 |
|
| 70 |
|
| 71 |
demo = gr.TabbedInterface(
|
| 72 |
-
[smiles_interface, mw_interface, logp_interface, tpsa_interface],
|
| 73 |
[
|
|
|
|
| 74 |
"SMILES to Canonical",
|
| 75 |
"Molecular Weight",
|
| 76 |
"LogP",
|
|
|
|
| 35 |
return Draw.MolToImage(mol)
|
| 36 |
|
| 37 |
|
| 38 |
+
def name_to_smiles(name: str) -> str:
|
| 39 |
+
"""Convert chemical name to SMILES using RDKit's name parsing"""
|
| 40 |
+
try:
|
| 41 |
+
mol = Chem.MolFromName(name)
|
| 42 |
+
if mol is None:
|
| 43 |
+
raise gr.Error(f"Could not parse chemical name: {name}")
|
| 44 |
+
return Chem.MolToSmiles(mol)
|
| 45 |
+
except Exception as e:
|
| 46 |
+
raise gr.Error(f"Error converting name to SMILES: {str(e)}")
|
| 47 |
+
|
| 48 |
+
|
| 49 |
smiles_interface = gr.Interface(
|
| 50 |
fn=smiles_to_canonical,
|
| 51 |
inputs=gr.Textbox(label="SMILES"),
|
|
|
|
| 54 |
description="Convert an input SMILES string to its canonical form.",
|
| 55 |
)
|
| 56 |
|
| 57 |
+
name_interface = gr.Interface(
|
| 58 |
+
fn=name_to_smiles,
|
| 59 |
+
inputs=gr.Textbox(label="Chemical Name", placeholder="e.g., aspirin, caffeine, benzene"),
|
| 60 |
+
outputs=gr.Textbox(label="SMILES"),
|
| 61 |
+
api_name="name_to_smiles",
|
| 62 |
+
description="Convert a chemical name to SMILES notation.",
|
| 63 |
+
examples=[["aspirin"], ["caffeine"], ["benzene"], ["ethanol"]],
|
| 64 |
+
)
|
| 65 |
+
|
| 66 |
mw_interface = gr.Interface(
|
| 67 |
fn=molecular_weight,
|
| 68 |
inputs=gr.Textbox(label="SMILES"),
|
|
|
|
| 89 |
|
| 90 |
|
| 91 |
demo = gr.TabbedInterface(
|
| 92 |
+
[name_interface, smiles_interface, mw_interface, logp_interface, tpsa_interface],
|
| 93 |
[
|
| 94 |
+
"Name to SMILES",
|
| 95 |
"SMILES to Canonical",
|
| 96 |
"Molecular Weight",
|
| 97 |
"LogP",
|