Spaces:
Sleeping
Sleeping
File size: 1,282 Bytes
faa9b70 544f1f3 faa9b70 544f1f3 faa9b70 544f1f3 faa9b70 544f1f3 faa9b70 544f1f3 faa9b70 544f1f3 faa9b70 544f1f3 faa9b70 544f1f3 faa9b70 544f1f3 faa9b70 544f1f3 faa9b70 544f1f3 faa9b70 544f1f3 cda2c63 544f1f3 faa9b70 544f1f3 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
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() |