Ayush0804 commited on
Commit
3415b9b
·
verified ·
1 Parent(s): 32af427

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +31 -24
app.py CHANGED
@@ -76,19 +76,15 @@ def math_chatbot(image, sketchpad, question, state):
76
  return get_math_response(image_description, question)
77
 
78
 
 
 
 
 
79
  css = """
80
  #qwen-md .katex-display { display: inline; }
81
  #qwen-md .katex-display>.katex { display: inline; }
82
  #qwen-md .katex-display>.katex>.katex-html { display: inline; }
83
  """
84
-
85
-
86
- # Tab selection callback
87
- def tabs_select(e: gr.SelectData, _state):
88
- _state["tab_index"] = e.index
89
-
90
-
91
- # Gradio interface
92
  with gr.Blocks(css=css) as demo:
93
  gr.HTML("""\
94
  <p align="center"><img src="https://huggingface.co/front/assets/huggingface_logo.svg" style="height: 60px"/><p>"""
@@ -97,24 +93,23 @@ with gr.Blocks(css=css) as demo:
97
  <center><font size=3>This demo uses Hugging Face models for OCR and mathematical reasoning. You can input images or text-based questions.</center>"""
98
  )
99
  state = gr.State({"tab_index": 0})
100
-
101
  with gr.Row():
102
  with gr.Column():
103
  with gr.Tabs() as input_tabs:
104
  with gr.Tab("Upload"):
105
- input_image = gr.Image(type="pil", label="Upload")
106
  with gr.Tab("Sketch"):
107
- input_sketchpad = gr.Sketchpad(label="Sketch", layers=False)
108
  input_tabs.select(fn=tabs_select, inputs=[state])
109
- input_text = gr.Textbox(label="Input your question")
110
  with gr.Row():
111
  with gr.Column():
112
- clear_btn = gr.ClearButton([input_image, input_sketchpad, input_text])
 
113
  with gr.Column():
114
  submit_btn = gr.Button("Submit", variant="primary")
115
-
116
  with gr.Column():
117
- output_md = gr.Markdown(label="Answer",
118
  latex_delimiters=[{
119
  "left": "\\(",
120
  "right": "\\)",
@@ -123,18 +118,30 @@ with gr.Blocks(css=css) as demo:
123
  "left": "\\begin\{equation\}",
124
  "right": "\\end\{equation\}",
125
  "display": True
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
126
  }, {
127
  "left": "\\[",
128
  "right": "\\]",
129
  "display": True
130
  }],
131
  elem_id="qwen-md")
132
-
133
- submit_btn.click(
134
- fn=math_chatbot,
135
- inputs=[input_image, input_sketchpad, input_text, state],
136
- outputs=output_md
137
- )
138
-
139
- # Launch Gradio app
140
- demo.launch()
 
76
  return get_math_response(image_description, question)
77
 
78
 
79
+
80
+ def tabs_select(e: gr.SelectData, _state):
81
+ _state["tab_index"] = e.index
82
+
83
  css = """
84
  #qwen-md .katex-display { display: inline; }
85
  #qwen-md .katex-display>.katex { display: inline; }
86
  #qwen-md .katex-display>.katex>.katex-html { display: inline; }
87
  """
 
 
 
 
 
 
 
 
88
  with gr.Blocks(css=css) as demo:
89
  gr.HTML("""\
90
  <p align="center"><img src="https://huggingface.co/front/assets/huggingface_logo.svg" style="height: 60px"/><p>"""
 
93
  <center><font size=3>This demo uses Hugging Face models for OCR and mathematical reasoning. You can input images or text-based questions.</center>"""
94
  )
95
  state = gr.State({"tab_index": 0})
 
96
  with gr.Row():
97
  with gr.Column():
98
  with gr.Tabs() as input_tabs:
99
  with gr.Tab("Upload"):
100
+ input_image = gr.Image(type="pil", label="Upload"),
101
  with gr.Tab("Sketch"):
102
+ input_sketchpad = gr.Sketchpad(type="pil", label="Sketch", layers=False)
103
  input_tabs.select(fn=tabs_select, inputs=[state])
104
+ input_text = gr.Textbox(label="input your question")
105
  with gr.Row():
106
  with gr.Column():
107
+ clear_btn = gr.ClearButton(
108
+ [*input_image, input_sketchpad, input_text])
109
  with gr.Column():
110
  submit_btn = gr.Button("Submit", variant="primary")
 
111
  with gr.Column():
112
+ output_md = gr.Markdown(label="answer",
113
  latex_delimiters=[{
114
  "left": "\\(",
115
  "right": "\\)",
 
118
  "left": "\\begin\{equation\}",
119
  "right": "\\end\{equation\}",
120
  "display": True
121
+ }, {
122
+ "left": "\\begin\{align\}",
123
+ "right": "\\end\{align\}",
124
+ "display": True
125
+ }, {
126
+ "left": "\\begin\{alignat\}",
127
+ "right": "\\end\{alignat\}",
128
+ "display": True
129
+ }, {
130
+ "left": "\\begin\{gather\}",
131
+ "right": "\\end\{gather\}",
132
+ "display": True
133
+ }, {
134
+ "left": "\\begin\{CD\}",
135
+ "right": "\\end\{CD\}",
136
+ "display": True
137
  }, {
138
  "left": "\\[",
139
  "right": "\\]",
140
  "display": True
141
  }],
142
  elem_id="qwen-md")
143
+ submit_btn.click(
144
+ fn=math_chat_bot,
145
+ inputs=[*input_image, input_sketchpad, input_text, state],
146
+ outputs=output_md)
147
+ demo.launch()