File size: 1,150 Bytes
bed5ef9
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import gradio as gr
import requests



def chatbot_qwen(prompt,history):  
        url = "https://qwen-3.p.rapidapi.com/chat/completions"

        payload = {
            "model": "qwen3-14b",
            "messages": [
                {
                    "role": "user",
                    "content": prompt
                }
            ]
        }
        headers = {
            "x-rapidapi-key": "3d66bcf268mshb7e2600a51aa227p1c07cajsn59f71d743737",
            "x-rapidapi-host": "qwen-3.p.rapidapi.com",
            "Content-Type": "application/json"
        }

        response = requests.post(url, json=payload, headers=headers)
        output = response.json()

        return output['choices'][0]['message']['content']

def vote(data: gr.LikeData):
    if data.liked:
        print("You upvoted this response: " + data.value["value"])
    else:
        print("You downvoted this response: " + data.value["value"])

with gr.Blocks() as demo:
    chatbot = gr.Chatbot(placeholder="<strong>Qwen Chatbot</strong><br>Ask Me Anything")
    chatbot.like(vote, None, None)
    gr.ChatInterface(fn=chatbot_qwen,chatbot=chatbot)
    
demo.launch()