Spaces:
Sleeping
Sleeping
| import gradio as gr | |
| import random | |
| from huggingface_hub import InferenceClient | |
| client = InferenceClient("Qwen/Qwen2.5-7B-Instruct") | |
| def random_response(message, history): | |
| messages = [{"role": "system", "content": "You are a friendly chatbot"}] | |
| if history: | |
| messages.extend(history) | |
| messages.append({"role": "user", "content": message}) | |
| response = "" | |
| for message in client.chat_completion( | |
| messages, | |
| max_tokens=1000, | |
| stream=True | |
| ): | |
| token = message.choices[0].delta.content | |
| if token is not None: | |
| response += token | |
| yield response | |
| #response_options = ["yes", "no", "I need more cosmic energy to answer.", "Very doubtful.", "Signs point to yes."] | |
| #return random.choices[0].message.content.strip() | |
| chatbot = gr.ChatInterface(random_response, title="Chatbot") | |
| chatbot.launch() | |