Spaces:
Sleeping
Sleeping
Create iupac2style.py
Browse files- interfaces/iupac2style.py +22 -0
interfaces/iupac2style.py
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
from chemicalconverters import NamesConverter
|
| 3 |
+
|
| 4 |
+
def convert(chemical_name, plot):
|
| 5 |
+
# Initialize the ChemicalConverter
|
| 6 |
+
converter = NamesConverter('knowledgator/IUPAC2SMILES-canonical-small')
|
| 7 |
+
converted_name = converter.iupac_to_smiles(chemical_name)[0][:6]
|
| 8 |
+
styles = {"<SYST>": "SYSTEMATIC", "<TRAD>": "TRADITIONAL", "<BASE>": "BASE"}
|
| 9 |
+
return styles.get(converted_name, "")
|
| 10 |
+
|
| 11 |
+
|
| 12 |
+
iupac2style = gr.Interface(
|
| 13 |
+
fn=convert,
|
| 14 |
+
allow_flagging='auto',
|
| 15 |
+
inputs=[
|
| 16 |
+
gr.Textbox(label="Enter your IUPAC name", placeholder="Enter IUPAC name here"),
|
| 17 |
+
],
|
| 18 |
+
outputs=[gr.Text(label="IUPAC style")],
|
| 19 |
+
examples=[
|
| 20 |
+
["propan-2-yl 2-[4-(4-chlorophenyl)carbonylphenoxy]-2-methyl-propanoate"]
|
| 21 |
+
],
|
| 22 |
+
)
|