maahikachitagi commited on
Commit
5669072
·
verified ·
1 Parent(s): eec6d8c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +16 -1
app.py CHANGED
@@ -1,9 +1,24 @@
1
  import gradio as gr
2
  import random
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3
 
4
  def echo(message, history):
5
  choices = ["Without a doubt", "Ask again later","Yes, definitely","Don't count on it"]
6
  response = random.choice(choices)
7
  return response
8
- chatbot = gr.ChatInterface(echo, type = "messages", examples = ["am I awesome", "Is it sunny today?", "r you okay?"], title = "8 ball chatbot")
9
  chatbot.launch()
 
1
  import gradio as gr
2
  import random
3
+ from huggingface_hub import InferenceClient
4
+
5
+
6
+ client = InferenceClient("HuggingFaceH4/zephyr-7b-beta")
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(
13
+ messages,
14
+ max_tokens = 100
15
+ )
16
+ print(response["choices"][0]["message"]["content"].strip())
17
+ return response["choices"][0]["message"]["content"].strip()
18
 
19
  def echo(message, history):
20
  choices = ["Without a doubt", "Ask again later","Yes, definitely","Don't count on it"]
21
  response = random.choice(choices)
22
  return response
23
+ chatbot = gr.ChatInterface(respond, type = "messages")
24
  chatbot.launch()