demetz commited on
Commit
ee24018
·
verified ·
1 Parent(s): 702327b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -5
app.py CHANGED
@@ -1,9 +1,11 @@
1
  import gradio as gr
2
  from huggingface_hub import InferenceClient
3
 
4
- client = InferenceClient("deepseek-ai/DeepSeek-R1-Distill-Qwen-32B")
5
 
6
  def respond(message, history):
 
 
7
 
8
  messages = [{"role": "system", "content": "You are a friendly chatbot."}]
9
 
@@ -12,14 +14,20 @@ def respond(message, history):
12
 
13
  messages.append({"role": "user", "content": message})
14
 
15
- response = client.chat_completion(
16
  messages,
17
  max_tokens=100,
18
- temperature=1.2
 
19
  )
20
-
21
- return response['choices'][0]['message']['content'].strip()
22
 
 
 
 
 
 
 
 
23
  chatbot = gr.ChatInterface(respond, type="messages")
24
 
25
  chatbot.launch()
 
1
  import gradio as gr
2
  from huggingface_hub import InferenceClient
3
 
4
+ client = InferenceClient("HuggingFaceH4/zephyr-7b-beta")
5
 
6
  def respond(message, history):
7
+
8
+ response=""
9
 
10
  messages = [{"role": "system", "content": "You are a friendly chatbot."}]
11
 
 
14
 
15
  messages.append({"role": "user", "content": message})
16
 
17
+ stream = client.chat_completion(
18
  messages,
19
  max_tokens=100,
20
+ temperature=1.2,
21
+ stream=True
22
  )
 
 
23
 
24
+ for message in stream:
25
+ token = message.choices[0].delta.content
26
+
27
+ if token is not None:
28
+ response += token
29
+ yield response
30
+
31
  chatbot = gr.ChatInterface(respond, type="messages")
32
 
33
  chatbot.launch()