mingbaer commited on
Commit
5e638d2
·
verified ·
1 Parent(s): 701d66d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +21 -4
app.py CHANGED
@@ -1,12 +1,29 @@
1
  import gradio as gr
2
  import random
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3
  # def yes_or_no(message, history):
4
  # return random.choice(['yes', 'no'])
5
  # def echo(message, history):
6
  # return message
7
- def magic_8_ball(message, history):
8
- return random.choice(['Try again later', 'Go for it!', 'IDK girl do you...', 'Definitely!!! Maybe....', "Danger! Don't you dare!", "I wouldn't do that if i were you", 'Absolutely', "That's a slay"])
9
  print("Hello, World!")
 
10
  # chatbot = gr.ChatInterface(yes_or_no, type="messages", examples=['yes queen', 'no way jose', 'hmmmm ot sure'], title='Ask me anything!', description='Ask the chatbot any yes or no question to get a response. Chatbot not liable for consequences of bad advice.')
11
- eight_ball = gr.ChatInterface(magic_8_ball, type="messages", examples=['Will I pass the test?', 'Do they like me?', 'Should I bring an umbrella with me?', 'Should I text my ex?'], title="Magic 8 Ball", description="Ask the chatbot any yes or no question to get a response. Chatbot not liable for consequences of bad advice.")
12
- eight_ball.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(
13
+ messages,
14
+ max_tokens=100
15
+ )
16
+ return response['choices'][0]['message']['content'].strip()
17
+
18
+ chatbot = gr.ChatInterface(respond, type="messages")
19
  # def yes_or_no(message, history):
20
  # return random.choice(['yes', 'no'])
21
  # def echo(message, history):
22
  # return message
23
+ # def magic_8_ball(message, history):
24
+ # return random.choice(['Try again later', 'Go for it!', 'IDK girl do you...', 'Definitely!!! Maybe....', "Danger! Don't you dare!", "I wouldn't do that if i were you", 'Absolutely', "That's a slay"])
25
  print("Hello, World!")
26
+ launch.chatbot()
27
  # chatbot = gr.ChatInterface(yes_or_no, type="messages", examples=['yes queen', 'no way jose', 'hmmmm ot sure'], title='Ask me anything!', description='Ask the chatbot any yes or no question to get a response. Chatbot not liable for consequences of bad advice.')
28
+ # eight_ball = gr.ChatInterface(magic_8_ball, type="messages", examples=['Will I pass the test?', 'Do they like me?', 'Should I bring an umbrella with me?', 'Should I text my ex?'], title="Magic 8 Ball", description="Ask the chatbot any yes or no question to get a response. Chatbot not liable for consequences of bad advice.")
29
+ # eight_ball.launch()