thomas0809 commited on
Commit
c157f5a
1 Parent(s): d7e790d

add markdown and examples

Browse files
app.py CHANGED
@@ -34,12 +34,29 @@ def get_markdown(reaction):
34
 
35
  def predict(image, molscribe, ocr):
36
  predictions = model.predict_image(image, molscribe=molscribe, ocr=ocr)
37
- pred_images = model.draw_predictions(predictions, image=image)
38
  markdown = [[i] + get_markdown(reaction) for i, reaction in enumerate(predictions)]
39
- return pred_images, markdown
40
 
41
 
42
  with gr.Blocks() as demo:
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
43
  with gr.Column():
44
  with gr.Row():
45
  image = gr.Image(label="Upload reaction diagram", show_label=False, type='pil').style(height=256)
@@ -48,9 +65,7 @@ with gr.Blocks() as demo:
48
  ocr = gr.Checkbox(label="Run OCR to recognize text")
49
  btn = gr.Button("Submit").style(full_width=False)
50
  with gr.Row():
51
- gallery = gr.Gallery(
52
- label="Predicted reactions", show_label=False, elem_id="gallery"
53
- ).style(height="auto")
54
  markdown = gr.Dataframe(
55
  headers=['#', 'reactant', 'condition', 'product'],
56
  datatype=['number'] + ['markdown'] * 3,
@@ -59,4 +74,11 @@ with gr.Blocks() as demo:
59
 
60
  btn.click(predict, inputs=[image, molscribe, ocr], outputs=[gallery, markdown])
61
 
 
 
 
 
 
 
 
62
  demo.launch()
 
34
 
35
  def predict(image, molscribe, ocr):
36
  predictions = model.predict_image(image, molscribe=molscribe, ocr=ocr)
37
+ pred_image = model.draw_predictions_combined(predictions, image=image)
38
  markdown = [[i] + get_markdown(reaction) for i, reaction in enumerate(predictions)]
39
+ return pred_image, markdown
40
 
41
 
42
  with gr.Blocks() as demo:
43
+ gr.Markdown("""
44
+ <center> <h1>RxnScribe</h1> </center>
45
+
46
+ Extract chemical reactions from a diagram. Please upload a reaction diagram, RxnScribe will predict the reaction structures in the diagram.
47
+
48
+ The predicted reactions are visualized in separate images.
49
+ <span style="color:red">**Red** boxes are <ins>*reactants*</ins>.</span>
50
+ <span style="color:green">**Green** boxes are <ins>*reaction conditions*</ins>.</span>
51
+ <span style="color:blue">**Blue** boxes are <ins>*products*</ins>.</span>
52
+
53
+ It usually takes 10-20 seconds to process a diagram with this demo.
54
+ Check the options to run [MolScribe](https://huggingface.co/spaces/yujieq/MolScribe) and [OCR](https://huggingface.co/spaces/tomofi/EasyOCR) (it will take a longer time, of course).
55
+
56
+ Code: https://github.com/thomas0809/RxnScribe
57
+
58
+ Authors: [Yujie Qian](mailto:[email protected]), Jiang Guo, Zhengkai Tu, Connor W. Coley, Regina Barzilay. _MIT CSAIL_.
59
+ """)
60
  with gr.Column():
61
  with gr.Row():
62
  image = gr.Image(label="Upload reaction diagram", show_label=False, type='pil').style(height=256)
 
65
  ocr = gr.Checkbox(label="Run OCR to recognize text")
66
  btn = gr.Button("Submit").style(full_width=False)
67
  with gr.Row():
68
+ gallery = gr.Image(label='Predicted reactions', show_label=True).style(height='auto')
 
 
69
  markdown = gr.Dataframe(
70
  headers=['#', 'reactant', 'condition', 'product'],
71
  datatype=['number'] + ['markdown'] * 3,
 
74
 
75
  btn.click(predict, inputs=[image, molscribe, ocr], outputs=[gallery, markdown])
76
 
77
+ gr.Examples(
78
+ examples=sorted(glob.glob('examples/*.png')),
79
+ inputs=[image],
80
+ outputs=[gallery, markdown],
81
+ fn=predict,
82
+ )
83
+
84
  demo.launch()
examples/acs.joc.5b02057-Scheme-c1.png ADDED
examples/acs.oprd.6b00128-Table-c2.png ADDED
examples/acs.orglett.5b01044-Table-c1.png ADDED
examples/acs.orglett.5b01309-Scheme-c6.png ADDED
examples/acs.orglett.5b01692-Scheme-c1.png ADDED
examples/acs.orglett.5b03104-Table-c1.png ADDED
examples/acs.orglett.5b03590-Table-c2.png ADDED
examples/jo501785d-Scheme-c1.png ADDED
examples/op7001694-Scheme-c2.png ADDED