thanglekdi commited on
Commit
90486e8
·
1 Parent(s): 7fe0df9

ok hông 2

Browse files
Files changed (1) hide show
  1. app.py +6 -5
app.py CHANGED
@@ -24,7 +24,7 @@ tokenizer = AutoTokenizer.from_pretrained(model_path, trust_remote_code=True)
24
  # 2️⃣ Hàm chat theo template “### Câu hỏi / ### Trả lời”
25
  PROMPT_TEMPLATE = "### Câu hỏi: {instruction}\n### Trả lời:"
26
 
27
- def respond(message, history, system_message, max_tokens, temperature, top_p):
28
  # 2.1 — Gom system message và history vào messages list
29
  messages = [{"role": "system", "content": system_message}]
30
  for u, b in history:
@@ -58,15 +58,16 @@ def respond(message, history, system_message, max_tokens, temperature, top_p):
58
 
59
  # 2.5 — Decode và tách phần assistant trả lời
60
  full = tokenizer.decode(outputs[0], skip_special_tokens=True)
61
- answer = full.replace(prompt, "").strip()
 
62
 
63
  # 2.6 — Cập nhật history và trả về
64
- history.append((message, answer))
65
- return history
66
 
67
  # 3️⃣ Giao diện Gradio
68
  demo = gr.ChatInterface(
69
- fn=respond,
70
  additional_inputs=[
71
  gr.Textbox("Bạn là một chatbot tiếng Việt thân thiện.", label="System message"),
72
  gr.Slider(1, 2048, value=512, step=1, label="Max new tokens"),
 
24
  # 2️⃣ Hàm chat theo template “### Câu hỏi / ### Trả lời”
25
  PROMPT_TEMPLATE = "### Câu hỏi: {instruction}\n### Trả lời:"
26
 
27
+ def respond(message, history: list[tuple[str, str]], system_message, max_tokens, temperature, top_p):
28
  # 2.1 — Gom system message và history vào messages list
29
  messages = [{"role": "system", "content": system_message}]
30
  for u, b in history:
 
58
 
59
  # 2.5 — Decode và tách phần assistant trả lời
60
  full = tokenizer.decode(outputs[0], skip_special_tokens=True)
61
+ response = full.replace(prompt, "").strip()
62
+ # yield response
63
 
64
  # 2.6 — Cập nhật history và trả về
65
+ # history.append((message, response))
66
+ # return history
67
 
68
  # 3️⃣ Giao diện Gradio
69
  demo = gr.ChatInterface(
70
+ respond,
71
  additional_inputs=[
72
  gr.Textbox("Bạn là một chatbot tiếng Việt thân thiện.", label="System message"),
73
  gr.Slider(1, 2048, value=512, step=1, label="Max new tokens"),