Spaces:
Sleeping
Sleeping
parvalijaved
commited on
Commit
β’
b9bb31b
1
Parent(s):
52cf704
Create iupac2smiles.py
Browse files- interfaces/iupac2smiles.py +28 -0
interfaces/iupac2smiles.py
ADDED
@@ -0,0 +1,28 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from rdkit_utils import plot_mol
|
3 |
+
from chemicalconverters import NamesConverter
|
4 |
+
|
5 |
+
def convert(chemical_name, plot):
|
6 |
+
# Initialize the ChemicalConverter
|
7 |
+
converter = NamesConverter('knowledgator/IUPAC2SMILES-canonical-small')
|
8 |
+
converted_name = ""
|
9 |
+
plot_image = None
|
10 |
+
converted_name = converter.iupac_to_smiles(chemical_name)[0][6:]
|
11 |
+
if plot:
|
12 |
+
plot_image = plot_mol(converted_name)
|
13 |
+
return converted_name, plot_image
|
14 |
+
|
15 |
+
|
16 |
+
iupac2smiles = gr.Interface(
|
17 |
+
fn=convert,
|
18 |
+
allow_flagging='auto',
|
19 |
+
inputs=[
|
20 |
+
gr.Textbox(label="Enter your IUPAC name", placeholder="Enter IUPAC name here"),
|
21 |
+
gr.Checkbox(label="Plot molecule", value=True)
|
22 |
+
],
|
23 |
+
outputs=[gr.Text(label="Converted Name"),
|
24 |
+
gr.Image(type='pil', label="Molecule Plot", height=170, width=890)],
|
25 |
+
examples=[
|
26 |
+
["ethanol", True]
|
27 |
+
],
|
28 |
+
)
|