Spaces:
Sleeping
Sleeping
Commit
·
af2c4a4
1
Parent(s):
e0a1da0
test deepseek
Browse files
app.py
CHANGED
|
@@ -1,64 +1,33 @@
|
|
| 1 |
-
|
| 2 |
-
import gradio as gr # type: ignore
|
| 3 |
-
import call_api
|
| 4 |
|
| 5 |
-
def
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
- Giữ nguyên các công thức LaTeX ở dạng [$…$] hoặc [$$…$$]
|
| 11 |
-
"""
|
| 12 |
-
lines = raw_reply.splitlines()
|
| 13 |
-
out_lines = []
|
| 14 |
-
for line in lines:
|
| 15 |
-
line = line.strip()
|
| 16 |
-
if not line:
|
| 17 |
-
continue
|
| 18 |
-
# In đậm tiêu đề bước
|
| 19 |
-
if line.startswith("Bước"):
|
| 20 |
-
out_lines.append(f"**{line}**")
|
| 21 |
-
else:
|
| 22 |
-
out_lines.append(line)
|
| 23 |
-
# Nối với paragraph spacing
|
| 24 |
-
return "\n\n".join(out_lines)
|
| 25 |
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
)
|
| 36 |
-
# 1. Gọi API gốc, lấy raw text
|
| 37 |
-
raw = call_api.call_deepseek(
|
| 38 |
-
message, history, system_message, max_tokens, temperature, top_p,
|
| 39 |
-
file_upload=file_upload, image_upload=image_upload
|
| 40 |
-
)
|
| 41 |
-
# 2. Format lại
|
| 42 |
-
formatted = format_reply(raw)
|
| 43 |
-
return formatted
|
| 44 |
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
# examples=[
|
| 58 |
-
# # Mỗi item: [message, system_message, max_tokens, temperature, top_p]
|
| 59 |
-
# ["tích phân của x^2 từ 0 đến 2 là gì? vui lòng lập luận từng bước", "bạn là nhà toán học, hãy viết dạng chữ bình thường, không dùng kí tự đặt biết", 500, 0.7, 0.95],
|
| 60 |
-
# ],
|
| 61 |
-
)
|
| 62 |
|
| 63 |
-
|
| 64 |
-
chat.launch()
|
|
|
|
| 1 |
+
import gradio as gr
|
|
|
|
|
|
|
| 2 |
|
| 3 |
+
def generate_markdown_response(message, history, system_message, max_tokens, temperature, top_p):
|
| 4 |
+
# Giả sử đây là kết quả gồm Markdown + LaTeX
|
| 5 |
+
md = f"""
|
| 6 |
+
**Bước 1**: Viết lại tích phân
|
| 7 |
+
$$\\int_0^2 x^2 \\,dx$$
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 8 |
|
| 9 |
+
**Bước 2**: Nguyên hàm
|
| 10 |
+
$$F(x)=\\frac{x^3}{3}$$
|
| 11 |
+
|
| 12 |
+
**Bước 3**: Giá trị
|
| 13 |
+
$$F(2)-F(0)=\\frac{8}{3}$$
|
| 14 |
+
|
| 15 |
+
**Kết luận**:
|
| 16 |
+
$$\\boxed{{\\int_0^2 x^2 \\,dx=\\frac{8}{3}}}$$
|
| 17 |
+
"""
|
| 18 |
+
return (None, md)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 19 |
|
| 20 |
+
with gr.Blocks() as demo:
|
| 21 |
+
chatbot = gr.Chatbot(type="messages")
|
| 22 |
+
md_output = gr.Markdown(
|
| 23 |
+
latex_delimiters=[{"left":"$$","right":"$$","display":True}]
|
| 24 |
+
)
|
| 25 |
+
txt = gr.Textbox(label="Nhập câu hỏi")
|
| 26 |
+
txt.submit(
|
| 27 |
+
generate_markdown_response,
|
| 28 |
+
inputs=[txt, chatbot, gr.Textbox(value="Bạn là chatbot toán học"),
|
| 29 |
+
gr.Slider(1,2048,200), gr.Slider(0.1,4.0,0.7), gr.Slider(0.1,1.0,0.95)],
|
| 30 |
+
outputs=[chatbot, md_output]
|
| 31 |
+
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 32 |
|
| 33 |
+
demo.launch()
|
|
|