thomas0809 commited on
Commit
e09f96a
1 Parent(s): 866233d

implement app.py; download ckpt from huggingface_hub

Browse files
.gitignore ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
 
1
+ *.ipynb
2
+ .ipynb_checkpoints/
3
+ flagged/
4
+ .DS_Store
5
+ **/.DS_Store
app.py CHANGED
@@ -1,7 +1,34 @@
1
  import gradio as gr
2
 
3
- def greet(name):
4
- return "Hello " + name + "!!"
 
 
5
 
6
- iface = gr.Interface(fn=greet, inputs="text", outputs="text")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
7
  iface.launch()
 
1
  import gradio as gr
2
 
3
+ import os
4
+ import glob
5
+ import torch
6
+ from molscribe import MolScribe
7
 
8
+ from huggingface_hub import hf_hub_download
9
+
10
+ REPO_ID = "yujieq/MolScribe"
11
+ FILENAME = "swin_base_char_aux_200k.pth"
12
+ ckpt_path = hf_hub_download(REPO_ID, FILENAME)
13
+
14
+ device = torch.device('cpu')
15
+ model = MolScribe(ckpt_path, device)
16
+
17
+ def predict(image):
18
+ smiles, molblock = model.predict_image(image)
19
+ return smiles, molblock
20
+
21
+ iface = gr.Interface(
22
+ predict,
23
+ inputs=gr.Image(label="Upload molecular image"),
24
+ outputs=[
25
+ gr.Textbox(label="SMILES"),
26
+ gr.Textbox(label="Molfile"),
27
+ ],
28
+ allow_flagging="auto",
29
+ title="MolScribe",
30
+ description="Convert a molecular image into SMILES and Molfile. Code: https://github.com/thomas0809/MolScribe",
31
+ examples=sorted(glob.glob('examples/*.png')),
32
+ examples_per_page=20,
33
+ )
34
  iface.launch()
examples/110.png ADDED
examples/12.png ADDED
examples/14.png ADDED
examples/18.png ADDED
examples/2.png ADDED
examples/4.png ADDED
examples/6.png ADDED
examples/64.png ADDED
examples/acs.oprd.5b00256-Scheme-c2-4.png ADDED
examples/acs.oprd.5b00371-Scheme-c5-6.png ADDED
examples/acs.orglett.5b01754-Scheme-c1-16.png ADDED
requirements.txt ADDED
@@ -0,0 +1 @@
 
 
1
+ git+https://github.com/thomas0809/MolScribe.git#egg=MolScribe