Spaces:
Sleeping
Sleeping
Update app.py
Browse files
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 |
-
<
|
141 |
-
|
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(
|
153 |
-
|
154 |
-
|
155 |
-
|
156 |
-
|
157 |
-
|
158 |
-
with gr.Column():
|
159 |
-
submit_btn = gr.Button("Submit", variant="primary")
|
160 |
with gr.Column():
|
161 |
-
output_md = gr.Markdown(
|
162 |
-
|
163 |
-
|
164 |
-
|
165 |
-
|
166 |
-
|
167 |
-
|
168 |
-
|
169 |
-
|
170 |
-
|
171 |
-
|
172 |
-
|
173 |
-
|
174 |
-
|
175 |
-
|
176 |
-
|
177 |
-
|
178 |
-
|
179 |
-
|
180 |
-
|
181 |
-
|
182 |
-
|
183 |
-
|
184 |
-
|
185 |
-
|
186 |
-
|
187 |
-
|
188 |
-
|
189 |
-
|
190 |
-
|
191 |
-
|
|
|
|
|
|
|
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()
|