MindVR commited on
Commit
c0eccc2
·
verified ·
1 Parent(s): c67107b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -5
app.py CHANGED
@@ -27,7 +27,13 @@ def build_prompt(history, new_message):
27
  return prompt
28
 
29
  def chat(history, new_message):
30
- # history: list[str], new_message: str
 
 
 
 
 
 
31
  prompt = build_prompt(history, new_message)
32
  input_ids = tokenizer(prompt, return_tensors="pt").input_ids.to(device)
33
  with torch.no_grad():
@@ -46,14 +52,13 @@ def chat(history, new_message):
46
  response = output_text.strip()
47
  return response
48
 
49
- # CHỈ DÙNG Gradio Interface, input là [history, new_message]
50
  iface = gr.Interface(
51
  fn=chat,
52
  inputs=[
53
- gr.inputs.Textbox(lines=8, label="History (JSON list, ví dụ: [\"User: Xin chào\"] )"),
54
- gr.inputs.Textbox(label="New message")
55
  ],
56
- outputs="text",
57
  title="MindVR Therapy Chatbot",
58
  allow_flagging="never"
59
  )
 
27
  return prompt
28
 
29
  def chat(history, new_message):
30
+ # Nếu history là chuỗi (do nhập tay trên UI), thì parse sang list
31
+ if isinstance(history, str):
32
+ try:
33
+ import ast
34
+ history = ast.literal_eval(history)
35
+ except:
36
+ history = [history]
37
  prompt = build_prompt(history, new_message)
38
  input_ids = tokenizer(prompt, return_tensors="pt").input_ids.to(device)
39
  with torch.no_grad():
 
52
  response = output_text.strip()
53
  return response
54
 
 
55
  iface = gr.Interface(
56
  fn=chat,
57
  inputs=[
58
+ gr.Textbox(lines=8, label="History (JSON list, ví dụ: [\"User: Xin chào\"] )"),
59
+ gr.Textbox(label="New message")
60
  ],
61
+ outputs=gr.Textbox(label="AI Response"),
62
  title="MindVR Therapy Chatbot",
63
  allow_flagging="never"
64
  )