Rialbox commited on
Commit
1e979ad
·
verified ·
1 Parent(s): 289fc49

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +46 -47
app.py CHANGED
@@ -136,62 +136,61 @@ def tabs_select(e: gr.SelectData, _state):
136
 
137
  # Create Gradio interface
138
  with gr.Blocks(css=css) as demo:
139
- gr.HTML("""\
140
- <p align="center"><img src="https://modelscope.oss-cn-beijing.aliyuncs.com/resource/qwen.png" style="height: 60px"/><p>"""
141
- """<center><font size=8>📖 Qwen2-Math Demo</center>"""
142
- """\
143
- <center><font size=3>This WebUI is based on Qwen2-VL for OCR and Qwen2-Math for mathematical reasoning. You can input either images or texts of mathematical or arithmetic problems.</center>"""
144
- )
145
  state = gr.State({"tab_index": 0})
146
  with gr.Row():
147
  with gr.Column():
148
  with gr.Tabs() as input_tabs:
149
  with gr.Tab("Upload"):
150
- input_image = gr.Image(type="pil", label="Upload")
151
  with gr.Tab("Sketch"):
152
- input_sketchpad = gr.Sketchpad(type="pil", label="Sketch", layers=False)
153
- input_tabs.select(fn=tabs_select, inputs=[state])
154
- input_text = gr.Textbox(label="Input your question")
155
- with gr.Row():
156
- with gr.Column():
157
- clear_btn = gr.ClearButton([input_image, input_sketchpad, input_text])
158
- with gr.Column():
159
- submit_btn = gr.Button("Submit", variant="primary")
160
  with gr.Column():
161
- output_md = gr.Markdown(label="answer",
162
- latex_delimiters=[{
163
- "left": "\\(",
164
- "right": "\\)",
165
- "display": True
166
- }, {
167
- "left": "\\begin\{equation\}",
168
- "right": "\\end\{equation\}",
169
- "display": True
170
- }, {
171
- "left": "\\begin\{align\}",
172
- "right": "\\end\{align\}",
173
- "display": True
174
- }, {
175
- "left": "\\begin\{alignat\}",
176
- "right": "\\end\{alignat\}",
177
- "display": True
178
- }, {
179
- "left": "\\begin\{gather\}",
180
- "right": "\\end\{gather\}",
181
- "display": True
182
- }, {
183
- "left": "\\begin\{CD\}",
184
- "right": "\\end\{CD\}",
185
- "display": True
186
- }, {
187
- "left": "\\[",
188
- "right": "\\]",
189
- "display": True
190
- }],
191
- elem_id="qwen-md")
 
 
 
192
  submit_btn.click(
193
  fn=math_chat_bot,
194
  inputs=[input_image, input_sketchpad, input_text, state],
195
- outputs=output_md)
 
196
 
197
  demo.launch()
 
136
 
137
  # Create Gradio interface
138
  with gr.Blocks(css=css) as demo:
139
+ gr.HTML(
140
+ """<center><h1>Qwen2-Math Demo</h1><p>Use either uploaded images or sketches for math-related problems.</p></center>"""
141
+ )
 
 
 
142
  state = gr.State({"tab_index": 0})
143
  with gr.Row():
144
  with gr.Column():
145
  with gr.Tabs() as input_tabs:
146
  with gr.Tab("Upload"):
147
+ input_image = gr.Image(type="pil", label="Upload Image")
148
  with gr.Tab("Sketch"):
149
+ input_sketchpad = gr.Sketchpad(label="Sketch Pad")
150
+
151
+ input_tabs.select(fn=lambda e: {"tab_index": e.index}, inputs=[], outputs=state)
152
+ input_text = gr.Textbox(label="Your Question")
153
+ submit_btn = gr.Button("Submit")
154
+
 
 
155
  with gr.Column():
156
+ output_md = gr.Markdown(
157
+ label="Answer",
158
+ latex_delimiters=[{
159
+ "left": "\\(",
160
+ "right": "\\)",
161
+ "display": True
162
+ }, {
163
+ "left": "\\begin{equation}",
164
+ "right": "\\end{equation}",
165
+ "display": True
166
+ }, {
167
+ "left": "\\begin{align}",
168
+ "right": "\\end{align}",
169
+ "display": True
170
+ }, {
171
+ "left": "\\begin{alignat}",
172
+ "right": "\\end{alignat}",
173
+ "display": True
174
+ }, {
175
+ "left": "\\begin{gather}",
176
+ "right": "\\end{gather}",
177
+ "display": True
178
+ }, {
179
+ "left": "\\begin{CD}",
180
+ "right": "\\end{CD}",
181
+ "display": True
182
+ }, {
183
+ "left": "\\[",
184
+ "right": "\\]",
185
+ "display": True
186
+ }],
187
+ elem_id="qwen-md"
188
+ )
189
+
190
  submit_btn.click(
191
  fn=math_chat_bot,
192
  inputs=[input_image, input_sketchpad, input_text, state],
193
+ outputs=output_md,
194
+ )
195
 
196
  demo.launch()