HelloSun commited on
Commit
d2a3b3c
·
verified ·
1 Parent(s): 3b22ee7

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +6 -3
app.py CHANGED
@@ -13,13 +13,16 @@ pipe = pipeline("text-generation", model=model, tokenizer=tokenizer)
13
 
14
  def respond(message, history):
15
  # 將當前訊息與歷史訊息合併
16
- input_text = message if not history else history[-1][1] + " " + message
17
  # 獲取模型的回應
18
  response = pipe(input_text, max_length=100, num_return_sequences=1)
19
- return response[0]['generated_text'], history + [(message, response[0]['generated_text'])]
 
 
 
20
 
21
  # 設定 Gradio 的聊天界面
22
- demo = gr.ChatInterface(fn=respond)
23
 
24
  if __name__ == "__main__":
25
  demo.launch()
 
13
 
14
  def respond(message, history):
15
  # 將當前訊息與歷史訊息合併
16
+ input_text = message if not history else history[-1]["content"] + " " + message
17
  # 獲取模型的回應
18
  response = pipe(input_text, max_length=100, num_return_sequences=1)
19
+ reply = response[0]['generated_text']
20
+
21
+ # 返回新的消息格式
22
+ return reply, history + [{"role": "user", "content": message}, {"role": "assistant", "content": reply}]
23
 
24
  # 設定 Gradio 的聊天界面
25
+ demo = gr.ChatInterface(fn=respond, title="Chat with Qwen 2.5", description="與 HelloSun/Qwen2.5-0.5B-Instruct-openvino 聊天!", type='messages')
26
 
27
  if __name__ == "__main__":
28
  demo.launch()