Spaces:
Running
Running
Commit
·
102aa00
1
Parent(s):
2e24e06
test deepseek
Browse files
app.py
CHANGED
@@ -2,8 +2,48 @@
|
|
2 |
import gradio as gr # type: ignore
|
3 |
import call_api
|
4 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
5 |
chat = gr.ChatInterface(
|
6 |
-
|
7 |
title="Trợ lý Học Tập AI",
|
8 |
description="Nhập câu hỏi của bạn về Toán, Lý, Hóa, Văn… và nhận giải đáp chi tiết ngay lập tức!",
|
9 |
additional_inputs=[
|
|
|
2 |
import gradio as gr # type: ignore
|
3 |
import call_api
|
4 |
|
5 |
+
def format_reply(raw_reply: str) -> str:
|
6 |
+
"""
|
7 |
+
Format lại chuỗi raw_reply thành Markdown-friendly:
|
8 |
+
- Chèn xuống dòng đôi để tạo paragraph rõ ràng
|
9 |
+
- In đậm các bước ('Bước 1:', 'Bước 2:', …)
|
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 |
+
def respond(
|
27 |
+
message,
|
28 |
+
history,
|
29 |
+
system_message,
|
30 |
+
max_tokens,
|
31 |
+
temperature,
|
32 |
+
top_p,
|
33 |
+
file_upload=None,
|
34 |
+
image_upload=None
|
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 |
chat = gr.ChatInterface(
|
46 |
+
respond, #chat
|
47 |
title="Trợ lý Học Tập AI",
|
48 |
description="Nhập câu hỏi của bạn về Toán, Lý, Hóa, Văn… và nhận giải đáp chi tiết ngay lập tức!",
|
49 |
additional_inputs=[
|