Spaces:
Running
Running
File size: 1,422 Bytes
7476d14 ce58ca9 7476d14 975e8b4 7476d14 ce58ca9 7476d14 ce58ca9 7476d14 ce58ca9 7476d14 5557d6a 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 31 32 33 34 35 36 37 38 |
import gradio as gr
from rdkit_utils import plot_mol
from chemicalconverters import NamesConverter
def convert(chemical_name, style, validate, plot):
# Initialize the ChemicalConverter
converter = NamesConverter("knowledgator/SMILES2IUPAC-canonical-base")
converted_name = ""
validation_score = ""
plot_image = None
style_prefix = "<" + style[:4] + ">"
if validate:
converted_name, validation_score = converter.smiles_to_iupac(style_prefix + chemical_name, validate=True)
else:
converted_name = converter.smiles_to_iupac(style_prefix + chemical_name)
if plot:
plot_image = plot_mol(chemical_name)
return converted_name[0], validation_score, plot_image
smiles2iupac = gr.Interface(
fn=convert,
allow_flagging='auto',
inputs=[
gr.Textbox(label="Enter your SMILES name", placeholder="Enter your SMILES name here"),
gr.Radio(
choices=["BASE", "SYSTEMATIC", "TRADITIONAL"],
label="Choose desired IUPAC style",
),
gr.Checkbox(label="Validate with molecular similarity", value=False),
gr.Checkbox(label="Plot molecule", value=True)
],
outputs=[gr.Text(label="Converted Name"),
gr.Text(label="Input-Target similarity score"),
gr.Image(type='pil', label="Molecule Plot", height=170, width=890)],
examples=[
["CCO", "BASE", True, True]
],
) |