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()