thomas0809 commited on
Commit
136efdc
1 Parent(s): 4e5731d

update MolScribe interface

Browse files
Files changed (2) hide show
  1. app.py +14 -9
  2. requirements.txt +4 -1
app.py CHANGED
@@ -18,6 +18,7 @@ ckpt_path = hf_hub_download(REPO_ID, FILENAME)
18
  device = torch.device('cpu')
19
  model = MolScribe(ckpt_path, device)
20
 
 
21
  def generate_mol_image(molblock):
22
  indigo = Indigo()
23
  render = IndigoRenderer(indigo)
@@ -30,10 +31,14 @@ def generate_mol_image(molblock):
30
  img = cv2.imdecode(np.asarray(bytearray(buf), dtype=np.uint8), 1)
31
  return img
32
 
 
33
  def predict(image):
34
- smiles, molblock = model.predict_image(image)
35
- image = generate_mol_image(molblock)
36
- return image, smiles, molblock
 
 
 
37
 
38
  iface = gr.Interface(
39
  predict,
@@ -45,12 +50,12 @@ iface = gr.Interface(
45
  ],
46
  allow_flagging="auto",
47
  title="MolScribe",
48
- description="Convert a molecular image into SMILES and Molfile. (It typically takes 2-3 seconds to predict an image, "
49
- "but may take longer if the server is busy. "
50
- "To view the prediction better, copy-paste the Molfile to ChemDraw.) <br> " \
51
- "Paper: [_MolScribe: Robust Molecular Structure Recognition with Image-To-Graph Generation_](https://arxiv.org/abs/2205.14311) <br>" \
52
- "Code: https://github.com/thomas0809/MolScribe <br>" \
53
- "Authors: [Yujie Qian](mailto:[email protected]), Jiang Guo, Zhengkai Tu, Zhening Li, Connor W. Coley, Regina Barzilay. _MIT CSAIL_.",
54
  examples=sorted(glob.glob('examples/*.png')),
55
  examples_per_page=20,
56
  )
 
18
  device = torch.device('cpu')
19
  model = MolScribe(ckpt_path, device)
20
 
21
+
22
  def generate_mol_image(molblock):
23
  indigo = Indigo()
24
  render = IndigoRenderer(indigo)
 
31
  img = cv2.imdecode(np.asarray(bytearray(buf), dtype=np.uint8), 1)
32
  return img
33
 
34
+
35
  def predict(image):
36
+ prediction = model.predict_image(image)
37
+ smiles = prediction['smiles']
38
+ molfile = prediction['molfile']
39
+ image = generate_mol_image(molfile)
40
+ return image, smiles, molfile
41
+
42
 
43
  iface = gr.Interface(
44
  predict,
 
50
  ],
51
  allow_flagging="auto",
52
  title="MolScribe",
53
+ description="Convert a molecular image into SMILES and Molfile. (It typically takes 2-3 seconds to predict an "
54
+ "image, but may take longer if the server is busy. To view the prediction better, copy-paste the "
55
+ "Molfile to ChemDraw.) <br> " \
56
+ "Paper: [_MolScribe: Robust Molecular Structure Recognition with Image-To-Graph Generation_](https://arxiv.org/abs/2205.14311) <br>" \
57
+ "Code: https://github.com/thomas0809/MolScribe <br>" \
58
+ "Authors: [Yujie Qian](mailto:[email protected]), Jiang Guo, Zhengkai Tu, Zhening Li, Connor W. Coley, Regina Barzilay. _MIT CSAIL_.",
59
  examples=sorted(glob.glob('examples/*.png')),
60
  examples_per_page=20,
61
  )
requirements.txt CHANGED
@@ -1,2 +1,5 @@
1
  git+https://github.com/thomas0809/MolScribe.git@main#egg=MolScribe
2
- epam.indigo==1.8.0
 
 
 
 
1
  git+https://github.com/thomas0809/MolScribe.git@main#egg=MolScribe
2
+ epam.indigo==1.8.0
3
+ transformers>=4.5.1
4
+ huggingface-hub>=0.11.0
5
+ matplotlib>=3.5.3