Spaces:
Sleeping
Sleeping
File size: 886 Bytes
87c8175 b7a97d7 306b173 ced5300 b7a97d7 ced5300 1d8e6c2 ced5300 1d8e6c2 e228e40 110689c ced5300 d71d258 e228e40 ced5300 1d8e6c2 87c8175 9500b4a 87c8175 | 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 | 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()
|