arohi-k commited on
Commit
75f6036
·
verified ·
1 Parent(s): 952b705

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +18 -1
app.py CHANGED
@@ -1,11 +1,28 @@
1
  import gradio as gr
2
  import random
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3
 
4
  def random_message(message, history):
5
  choices = ["it is likely", "absolutely not", "try again", "without a doubt", "outlook good", "signs point to it", "very unlikely", "quite doubtful"]
6
  chat_answer = random.choice(choices)
7
  return chat_answer
8
 
9
- chatbot = gr.ChatInterface(random_message, type = "messages", title = "Random Response Chatbot", description = "<center> ask me a question, i'll give you the answer")
10
 
11
  chatbot.launch()
 
1
  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
+
9
+ messages = [{"role": "system", "content": "You are a friendly chatbot."}]
10
+ if history:
11
+ messages.extend(history)
12
+
13
+ messages.append({"role" : "user", "content" : message})
14
+
15
+ response = client.chat_completion(messages, max_tokens = 100)
16
+
17
+ print(response["choices"][0]["message"]["content"].strip())
18
+
19
+ return response["choices"][0]["message"]["content"].strip()
20
 
21
  def random_message(message, history):
22
  choices = ["it is likely", "absolutely not", "try again", "without a doubt", "outlook good", "signs point to it", "very unlikely", "quite doubtful"]
23
  chat_answer = random.choice(choices)
24
  return chat_answer
25
 
26
+ chatbot = gr.ChatInterface(respond, type = "messages")
27
 
28
  chatbot.launch()