Janec09 commited on
Commit
62deafe
Β·
verified Β·
1 Parent(s): be89b48

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -8
app.py CHANGED
@@ -2,23 +2,22 @@ import gradio as gr
2
  import random
3
  from huggingface_hub import InferenceClient
4
 
5
- client = InferenceClient(β€œHuggingFaceH4/zephyr-7b-beta”)
6
 
7
  def respond(message, history):
8
- messages = [{β€œrole”: β€œsystem”, β€œcontent”: β€œYou are a friendly chatbot.β€œ}]
9
-
10
  if history:
11
  messages.extend(history)
12
- messages.append({β€œrole”: β€œuser”, β€œcontent”: message})
13
- response = client.chat_completion(messages, max_tokens = 100)
14
- return response[β€˜choices’][0][β€˜message’][β€˜content’].strip()
15
 
16
  def echo(message, history):
17
  return message
18
 
19
  def yes_no(message, history):
20
- responses = [β€œYes”, β€œNo”]
21
  return random.choice(responses)
22
 
23
- chatbot = gr.ChatInterface(respond, type=β€œmessages”)
24
  chatbot.launch()
 
2
  import random
3
  from huggingface_hub import InferenceClient
4
 
5
+ client = InferenceClient("HuggingFaceH4/zephyr-7b-beta")
6
 
7
  def respond(message, history):
8
+ messages = [{"role": "system", "content": "You are a friendly chatbot."}]
 
9
  if history:
10
  messages.extend(history)
11
+ messages.append({"role": "user", "content": message})
12
+ response = client.chat_completion(messages, max_tokens = 100)
13
+ return response["choices"][0]["message"]["content"].strip()
14
 
15
  def echo(message, history):
16
  return message
17
 
18
  def yes_no(message, history):
19
+ responses = ["Yes", "No"]
20
  return random.choice(responses)
21
 
22
+ chatbot = gr.ChatInterface(respond, type="messages")
23
  chatbot.launch()