Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,30 +1,30 @@
|
|
| 1 |
-
import numpy as np # linear algebra
|
| 2 |
-
import pandas as pd
|
| 3 |
-
import torch
|
| 4 |
-
from molscribe import MolScribe
|
| 5 |
-
from huggingface_hub import hf_hub_download
|
| 6 |
-
import gradio as gr
|
| 7 |
-
from rdkit import Chem
|
| 8 |
-
from PIL import Image
|
| 9 |
-
import io
|
| 10 |
-
|
| 11 |
-
ckpt_path = hf_hub_download('yujieq/MolScribe', 'swin_base_char_aux_1m.pth')
|
| 12 |
-
model = MolScribe(ckpt_path, device=torch.device('cpu'))
|
| 13 |
-
|
| 14 |
-
def make_smiles(img):
|
| 15 |
-
'''
|
| 16 |
-
'''
|
| 17 |
-
output = model.predict_image_file(img, return_atoms_bonds=True, return_confidence=True)
|
| 18 |
-
mol = Chem.MolFromSmiles(output['smiles'])
|
| 19 |
-
new_img_raw = Chem.Draw.MolsToGridImage([mol], molsPerRow=1, legends=[output['smiles']])
|
| 20 |
-
new_img = Image.open(io.BytesIO(new_img_raw.data))
|
| 21 |
-
return output['smiles'], new_img
|
| 22 |
-
|
| 23 |
-
demo = gr.Interface(
|
| 24 |
-
fn = make_smiles,
|
| 25 |
-
inputs=gr.Image(type="filepath"),
|
| 26 |
-
outputs=[gr.Textbox(lines=2, label="SMILES"), gr.Image(label="New Image")],
|
| 27 |
-
title="MolScribe",
|
| 28 |
-
)
|
| 29 |
-
|
| 30 |
-
demo.launch(
|
|
|
|
| 1 |
+
import numpy as np # linear algebra
|
| 2 |
+
import pandas as pd
|
| 3 |
+
import torch
|
| 4 |
+
from molscribe import MolScribe
|
| 5 |
+
from huggingface_hub import hf_hub_download
|
| 6 |
+
import gradio as gr
|
| 7 |
+
from rdkit import Chem
|
| 8 |
+
from PIL import Image
|
| 9 |
+
import io
|
| 10 |
+
|
| 11 |
+
ckpt_path = hf_hub_download('yujieq/MolScribe', 'swin_base_char_aux_1m.pth')
|
| 12 |
+
model = MolScribe(ckpt_path, device=torch.device('cpu'))
|
| 13 |
+
|
| 14 |
+
def make_smiles(img):
|
| 15 |
+
'''
|
| 16 |
+
'''
|
| 17 |
+
output = model.predict_image_file(img, return_atoms_bonds=True, return_confidence=True)
|
| 18 |
+
mol = Chem.MolFromSmiles(output['smiles'])
|
| 19 |
+
new_img_raw = Chem.Draw.MolsToGridImage([mol], molsPerRow=1, legends=[output['smiles']])
|
| 20 |
+
new_img = Image.open(io.BytesIO(new_img_raw.data))
|
| 21 |
+
return output['smiles'], new_img
|
| 22 |
+
|
| 23 |
+
demo = gr.Interface(
|
| 24 |
+
fn = make_smiles,
|
| 25 |
+
inputs=gr.Image(type="filepath"),
|
| 26 |
+
outputs=[gr.Textbox(lines=2, label="SMILES"), gr.Image(label="New Image")],
|
| 27 |
+
title="MolScribe",
|
| 28 |
+
)
|
| 29 |
+
|
| 30 |
+
demo.launch(mcp_server=True)
|