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