LayaPrakash commited on
Commit
4a4d15c
·
verified ·
1 Parent(s): 27f7078

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -2
app.py CHANGED
@@ -2,6 +2,7 @@ import gradio as gr
2
  import random
3
  from huggingface_hub import InferenceClient
4
 
 
5
  client = InferenceClient("Qwen/Qwen2.5-72B-Instruct")
6
 
7
  def respond(message, history):
@@ -9,7 +10,12 @@ def respond(message, history):
9
  if history:
10
  messages.extend(history)
11
  messages.append({"role" : "user", "content" : message})
12
- response = client.chat_completion(messages, max_tokens = 100)
 
 
 
 
 
13
  print(response["choices"][0]["message"]["content"].strip())
14
  return response["choices"][0]["message"]["content"].strip()
15
 
@@ -17,7 +23,9 @@ def echo(message, history):
17
  choices = ["yes", "no", "sure", "absolutely", "of course not", "by no means"]
18
  chat_answer = random.choice(choices)
19
  #use random to select ones of those choices
20
- return chat_answer
 
 
21
 
22
  chatbot = gr.ChatInterface(respond, type = 'messages')
23
 
 
2
  import random
3
  from huggingface_hub import InferenceClient
4
 
5
+
6
  client = InferenceClient("Qwen/Qwen2.5-72B-Instruct")
7
 
8
  def respond(message, history):
 
10
  if history:
11
  messages.extend(history)
12
  messages.append({"role" : "user", "content" : message})
13
+ response = ""
14
+ for message in client.chat_completion(
15
+ messages,
16
+ max_tokens = 100,
17
+ stream = True,
18
+ ):
19
  print(response["choices"][0]["message"]["content"].strip())
20
  return response["choices"][0]["message"]["content"].strip()
21
 
 
23
  choices = ["yes", "no", "sure", "absolutely", "of course not", "by no means"]
24
  chat_answer = random.choice(choices)
25
  #use random to select ones of those choices
26
+ token = messages.choices[0].delta.content
27
+ response += token
28
+ yield response
29
 
30
  chatbot = gr.ChatInterface(respond, type = 'messages')
31