Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -2,34 +2,25 @@ import gradio as gr
|
|
| 2 |
import random as rd
|
| 3 |
from huggingface_hub import InferenceClient
|
| 4 |
|
| 5 |
-
|
| 6 |
-
|
| 7 |
client = InferenceClient("Qwen/Qwen2.5-72B-Instruct")
|
| 8 |
def respond (message, history):
|
| 9 |
messages = [{"role": "system", "content": "You are a chatbot who is sassy and doesnt explain an anser unless someone asks twice."}]
|
| 10 |
if history:
|
| 11 |
messages.extend(history)
|
| 12 |
messages.append({"role": "user", "content": message})
|
| 13 |
-
response =
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
def echo (message, history):
|
| 27 |
-
eight_ball_answers = ["yes","no","ehhh probably not the best idea","Sure why not!","idk","i seems not","hahahaha... no","yes of course!"]
|
| 28 |
-
random_choice = rd.choice(eight_ball_answers)
|
| 29 |
-
return random_choice
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
chatbot = gr.ChatInterface(respond, type = "messages")
|
| 34 |
chatbot.launch(debug=True)
|
| 35 |
|
|
|
|
| 2 |
import random as rd
|
| 3 |
from huggingface_hub import InferenceClient
|
| 4 |
|
|
|
|
|
|
|
| 5 |
client = InferenceClient("Qwen/Qwen2.5-72B-Instruct")
|
| 6 |
def respond (message, history):
|
| 7 |
messages = [{"role": "system", "content": "You are a chatbot who is sassy and doesnt explain an anser unless someone asks twice."}]
|
| 8 |
if history:
|
| 9 |
messages.extend(history)
|
| 10 |
messages.append({"role": "user", "content": message})
|
| 11 |
+
response = “”
|
| 12 |
+
for message in client.chat_completion(
|
| 13 |
+
messages,
|
| 14 |
+
max_tokens=500,
|
| 15 |
+
temperature=0.2,
|
| 16 |
+
top_p=0.9,
|
| 17 |
+
stream=True
|
| 18 |
+
):
|
| 19 |
+
token = message.choices[0].delta.content
|
| 20 |
+
response += token
|
| 21 |
+
yield response['choices'][0]['message']['content'].strip()
|
| 22 |
+
|
| 23 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 24 |
chatbot = gr.ChatInterface(respond, type = "messages")
|
| 25 |
chatbot.launch(debug=True)
|
| 26 |
|