Update app.py
Browse files
app.py
CHANGED
@@ -61,15 +61,76 @@ def math_chat_bot(image, sketchpad, question, state):
|
|
61 |
image_description = process_image(sketchpad["composite"], True)
|
62 |
yield from get_math_response(image_description, question)
|
63 |
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
gr.Slider(minimum=0.1, maximum=4.0, value=0.7, step=0.1, label="Temperature"),
|
70 |
-
gr.Slider(minimum=0.1, maximum=1.0, value=0.95, step=0.05, label="Top-p (nucleus sampling)"),
|
71 |
-
],
|
72 |
-
)
|
73 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
74 |
if __name__ == "__main__":
|
75 |
demo.launch()
|
|
|
61 |
image_description = process_image(sketchpad["composite"], True)
|
62 |
yield from get_math_response(image_description, question)
|
63 |
|
64 |
+
css = """
|
65 |
+
#qwen-md .katex-display { display: inline; }
|
66 |
+
#qwen-md .katex-display>.katex { display: inline; }
|
67 |
+
#qwen-md .katex-display>.katex>.katex-html { display: inline; }
|
68 |
+
"""
|
|
|
|
|
|
|
|
|
69 |
|
70 |
+
def tabs_select(e: gr.SelectData, _state):
|
71 |
+
_state["tab_index"] = e.index
|
72 |
+
|
73 |
+
|
74 |
+
# 创建Gradio接口
|
75 |
+
with gr.Blocks(css=css) as demo:
|
76 |
+
gr.HTML("""\
|
77 |
+
<p align="center"><img src="https://modelscope.oss-cn-beijing.aliyuncs.com/resource/qwen.png" style="height: 60px"/><p>"""
|
78 |
+
"""<center><font size=8>📖 Qwen2-Math Demo</center>"""
|
79 |
+
"""\
|
80 |
+
<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>"""
|
81 |
+
)
|
82 |
+
state = gr.State({"tab_index": 0})
|
83 |
+
with gr.Row():
|
84 |
+
with gr.Column():
|
85 |
+
with gr.Tabs() as input_tabs:
|
86 |
+
with gr.Tab("Upload"):
|
87 |
+
input_image = gr.Image(type="pil", label="Upload"),
|
88 |
+
with gr.Tab("Sketch"):
|
89 |
+
input_sketchpad = gr.Sketchpad(type="pil", label="Sketch", layers=False)
|
90 |
+
input_tabs.select(fn=tabs_select, inputs=[state])
|
91 |
+
input_text = gr.Textbox(label="input your question")
|
92 |
+
with gr.Row():
|
93 |
+
with gr.Column():
|
94 |
+
clear_btn = gr.ClearButton(
|
95 |
+
[*input_image, input_sketchpad, input_text])
|
96 |
+
with gr.Column():
|
97 |
+
submit_btn = gr.Button("Submit", variant="primary")
|
98 |
+
with gr.Column():
|
99 |
+
output_md = gr.Markdown(label="answer",
|
100 |
+
latex_delimiters=[{
|
101 |
+
"left": "\\(",
|
102 |
+
"right": "\\)",
|
103 |
+
"display": True
|
104 |
+
}, {
|
105 |
+
"left": "\\begin\{equation\}",
|
106 |
+
"right": "\\end\{equation\}",
|
107 |
+
"display": True
|
108 |
+
}, {
|
109 |
+
"left": "\\begin\{align\}",
|
110 |
+
"right": "\\end\{align\}",
|
111 |
+
"display": True
|
112 |
+
}, {
|
113 |
+
"left": "\\begin\{alignat\}",
|
114 |
+
"right": "\\end\{alignat\}",
|
115 |
+
"display": True
|
116 |
+
}, {
|
117 |
+
"left": "\\begin\{gather\}",
|
118 |
+
"right": "\\end\{gather\}",
|
119 |
+
"display": True
|
120 |
+
}, {
|
121 |
+
"left": "\\begin\{CD\}",
|
122 |
+
"right": "\\end\{CD\}",
|
123 |
+
"display": True
|
124 |
+
}, {
|
125 |
+
"left": "\\[",
|
126 |
+
"right": "\\]",
|
127 |
+
"display": True
|
128 |
+
}],
|
129 |
+
elem_id="qwen-md")
|
130 |
+
submit_btn.click(
|
131 |
+
fn=math_chat_bot,
|
132 |
+
inputs=[*input_image, input_sketchpad, input_text, state],
|
133 |
+
outputs=output_md)
|
134 |
+
|
135 |
if __name__ == "__main__":
|
136 |
demo.launch()
|