hsuwill000's picture
Update app.py
cda2c63 verified
import gradio as gr
from gradio_client import Client
# ๅˆๅง‹ๅŒ– Hugging Face Space ็š„ Client
client = Client("Qwen/Qwen2.5-72B-Instruct")
history = []
def respond(prompt, fhistory):
global history
messages = [{"role": "system", "content": "You are a helpful assistant."}]
for user_text, assistant_text in history:
messages.append({"role": "user", "content": user_text})
messages.append({"role": "assistant", "content": assistant_text})
messages.append({"role": "user", "content": prompt})
result = client.predict(
query=messages,
history=history,
system="You are a helpful assistant.",
api_name="/model_chat"
)
print(result)
response = result[1][-1][1] # ็ฒๅ–ๆœ€ๆ–ฐ็š„ AI ๅ›žๆ‡‰
history.append((prompt, response))
# **ๅ›žๅ‚ณ็ฌฆๅˆ ChatInterface ๆ ผๅผ**
#return [{"role": "user", "content": prompt}, {"role": "assistant", "content": response}]
return [{"role": "assistant", "content": response}]
# ่จญๅฎš Gradio ็š„่Šๅคฉ็•Œ้ข
demo = gr.ChatInterface(
fn=respond,
title="Qwen2.5-72B-Instruct Demo",
description="้€้Ž Hugging Face Space API ่ˆ‡ Qwen 2.5 Max ๆจกๅž‹ไบ’ๅ‹•ใ€‚",
type='messages'
)
if __name__ == "__main__":
demo.launch()