Spaces:
Runtime error
Runtime error
| __all__ = ['learn', 'classify_image', 'categories', 'image', 'label', 'examples', 'intf'] | |
| import gradio as gr | |
| from fastai.vision.all import * | |
| from PIL import Image | |
| import rdkit | |
| from rdkit import Chem | |
| from rdkit.Chem import Draw | |
| learn = load_learner('model.pkl') | |
| categories = ("Acid", "Base", "Neutral", "Zwitterion") | |
| def classify_image(SMILES): | |
| mol = Chem.MolFromSmiles(SMILES) | |
| Chem.Draw.MolToFile(mol, f'./{SMILES}.png') | |
| img = PILImage.create(f'./{SMILES}.png') | |
| pred,idx,probs = learn.predict(img) | |
| Probabilities = dict(zip(categories, map(float,probs))) | |
| Structure = img | |
| return Probabilities, Structure | |
| image = gr.inputs.Image(shape=(192, 192)) | |
| label = gr.outputs.Label() | |
| path = './test/' | |
| examples = [ | |
| "O=C(C)Oc1ccccc1C(=O)O", | |
| "C1=CNC=C1", | |
| "CC(O)=O", | |
| "CCN(CC)CC", | |
| "C1=CC2=C(C=C1O)C(=CN2)CCN", | |
| "OC[C@H]1OC(O)[C@H](O)[C@@H](O)[C@@H]1O C([C@@H]1[C@H]([C@@H]([C@H]([C@H](O1)O)O)O)O)O", | |
| "OC(=O)CC1CNCC2=C1C=CC=C2", | |
| "CN1CC(CN2C3=CC=C(Cl)C=C3C=NCC2=O)C1", | |
| "OC(=O)C1CN2CCC1CC2", | |
| "CS(=O)(=S)NC(=O)C1CC2CCC1CC2", | |
| ] | |
| intf = gr.Interface( | |
| fn=classify_image, | |
| inputs=gr.Textbox(lines=1, placeholder="Enter SMILES String Here..."), | |
| outputs=[label, image], | |
| examples=examples) | |
| intf.launch(inline=False) |