Update app.py
Browse files
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][
|
| 17 |
# 獲取模型的回應
|
| 18 |
response = pipe(input_text, max_length=100, num_return_sequences=1)
|
| 19 |
-
|
|
|
|
|
|
|
|
|
|
| 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()
|