Spaces:
Sleeping
Sleeping
File size: 1,280 Bytes
ada0283 4f86ed8 b94d71c ada0283 310a18a c0f9890 b94d71c 1f23eea b94d71c 1f23eea 00a2dc5 1f23eea 24ed7e4 1f23eea 48139f5 c0f9890 b94d71c a3dd3c4 b94d71c 65fdc13 6801f60 65fdc13 b94d71c ada0283 0320a5f |
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 |
import gradio as gr
import random
from huggingface_hub import InferenceClient
client = InferenceClient("Qwen/Qwen2.5-72B-Instruct")
#change the LLM
def respond(message, history):
messages = [{"role": "system", "content": "You are a sassy chatbot."}] #change the personality
if history:
messages.extend(history)
messages.append({"role":"user", "content": message})
response = ""
for message in client.chat_completion(
messages,
max_tokens=500,
stream=True,
#temperature = 0.3,
#top_p = 0.3
):
token = message.choices[0].delta.content
response += token
yield response
# change length using max_tokens
print(response['choices'][0]['message']['content'].strip())
def random_message(message, history):
choices = ["yes.", "no.", "it is certain","without a doubt","outlook good","ask again later", "better not tell you now","very doubtful","don't count on it","my sources say no","outlook not so good","very doubtful","reply hazy, try again", "cannot predict now"]
chat_answer = random.choice(choices)
return chat_answer
print("Hello, World!")
chatbot = gr.ChatInterface(respond, type = "messages")
chatbot.launch(debug=True) |