Files changed (1) hide show
  1. app.py +21 -4
app.py CHANGED
@@ -1,5 +1,9 @@
1
  import gradio as gr
2
  import random
 
 
 
 
3
 
4
  #def respond_yes_no_random(message, history):
5
  # responses = ["yes", "no"]
@@ -7,11 +11,24 @@ import random
7
 
8
  #chatbot = gr.ChatInterface(respond_yes_no_random, type = "messages", examples = ["HELLO", "Bye!"], title = "Annie's ChatBot")
9
 
10
- def magic_eight_ball(message, history):
11
- responses = ["It is certain", "It is decidedly so", "Without a doubt", "Yes definitely", "Most likely", "Outlook good", "Signs point to yes", "Ask again later", "Better not tell you now", "Cannot predict now", "Concentrate and ask again", "Perhaps", "Don't count on it", "My reply is no", "My sources say no", "Outlook not so good", "Very doubtful"]
12
- return random.choice(responses)
 
 
 
 
 
 
 
 
 
 
 
 
 
13
 
14
- chatbot = gr.ChatInterface(magic_eight_ball, type = "messages", examples = ["Will I win the lottery?", "When will I meet my soulmate?", "How will my day go today?"])
15
 
16
  chatbot.launch()
17
 
 
1
  import gradio as gr
2
  import random
3
+ import os
4
+ from huggingface_hub import InferenceClient
5
+
6
+ client = InferenceClient("HuggingFaceH4/zephyr-7b-beta")
7
 
8
  #def respond_yes_no_random(message, history):
9
  # responses = ["yes", "no"]
 
11
 
12
  #chatbot = gr.ChatInterface(respond_yes_no_random, type = "messages", examples = ["HELLO", "Bye!"], title = "Annie's ChatBot")
13
 
14
+ def respond(message, history):
15
+ messages = [{"role": "system", "content": "You are a vampire!"}]
16
+
17
+ if history:
18
+ messages.extend(history)
19
+
20
+ messages.append({"role":"user","content": message"})
21
+
22
+ response = client.chat_completion(
23
+ messages,
24
+ max_tokens=100
25
+ )
26
+
27
+ return response['choice'][0]['message']['content'].strip()
28
+
29
+
30
 
31
+ chatbot = gr.ChatInterface(respond, type = "messages")
32
 
33
  chatbot.launch()
34