File size: 1,041 Bytes
7476d14
6790366
7476d14
baf58cd
 
d0e2aff
7476d14
 
 
 
 
 
 
 
 
 
 
 
 
 
0df9304
7476d14
 
 
 
 
 
cb3a9cc
7476d14
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import gradio as gr
from utils import ChemicalConverter, validate_smiles2iupac, plot_mol, login

def convert(access_code, chemical_name, plot):
    if not login(access_code):
        return "Currently, you don't have access to the service.", plot_mol("CCO")
    # Initialize the ChemicalConverter
    converter = ChemicalConverter(mode="IUPAC2SMILES")
    converted_name = ""
    plot_image = None
    converted_name = converter.convert(chemical_name)[6:]
    if plot:
        plot_image = plot_mol(converted_name)
    return converted_name, plot_image


iupac2smiles = gr.Interface(
    fn=convert,
    allow_flagging='auto',
    inputs=[
        gr.Textbox(label="Enter your access code", placeholder=""),
        gr.Textbox(label="Enter your IUPAC name", placeholder="Enter IUPAC name here"),
        gr.Checkbox(label="Plot molecule", value=True)
    ],
    outputs=[gr.Text(label="Converted Name"),
             gr.Image(type='pil', label="Molecule Plot", height=170, width=890)],
    examples=[
        [None, "ethanol", True]
    ],
)