Pengi5659 commited on
Commit
422d839
·
verified ·
1 Parent(s): 6c6ffbf

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -22
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 = client.chat_completion(
14
- messages,
15
- max_tokens=100,
16
- temperature =.9,
17
- top_p=.7
18
-
19
-
20
- )
21
- print(response['choices'][0]['message']['content'].strip())
22
- return response['choices'][0]['message']['content'].strip()
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