anna1au commited on
Commit
67d3db1
·
verified ·
1 Parent(s): f981df2

Connected chatbot to LLM

Browse files
Files changed (1) hide show
  1. app.py +12 -1
app.py CHANGED
@@ -1,5 +1,16 @@
1
  import gradio as gr
2
  import random
 
 
 
 
 
 
 
 
 
 
 
3
 
4
  def yes_or_no(message, history):
5
  return random.choice(["Yes","No"])
@@ -8,5 +19,5 @@ def magic8(message, history):
8
  return random.choice(["Maybe... Let's see your luck!", "Of course! Don't even doubt it.", "Of course NOT! There's no chance!", "Try again", "Never in a billion years", "Is the sky blue?"])
9
 
10
  print ("Hello, world!")
11
- chatBot = gr.ChatInterface(magic8, type = "messages", title = "Magic 8 Ball", description = "Ask me a question if you dare!", theme = "earneleh/paris")
12
  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
+ 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 yes_or_no(message, history):
16
  return random.choice(["Yes","No"])
 
19
  return random.choice(["Maybe... Let's see your luck!", "Of course! Don't even doubt it.", "Of course NOT! There's no chance!", "Try again", "Never in a billion years", "Is the sky blue?"])
20
 
21
  print ("Hello, world!")
22
+ chatBot = gr.ChatInterface(respond, type = "messages", title = "Magic 8 Ball", description = "Ask me a question if you dare!", theme = "earneleh/paris")
23
  chatBot.launch()