mgetz commited on
Commit
1dd21bb
·
verified ·
1 Parent(s): 84a09c7

Convert magic eightball to AI chatbot

Browse files
Files changed (1) hide show
  1. app.py +31 -9
app.py CHANGED
@@ -1,19 +1,41 @@
1
  import gradio as gr
2
  import random
 
3
 
4
- def echo(message, history):
5
- return message
6
 
7
- def yes_no(message, history):
8
- responses = ["Yes", "No"]
9
- return random.choice(responses)
10
 
11
- def magic_eight(message, history):
12
- responses = ["That's a terrible question. Try again", "I don't think I should answer that...", "What do you think, genius?", "You are a bad person for asking that.", "Absolutely not", "Uuuuh, obviously.", "Of all the things you could ask, you went with that?", "I don't know, look it up", "I mean, yeah, I guess...", "That's gonna be a big nope", ""]
13
- return random.choice(responses)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
14
 
15
  with gr.Blocks(theme='mgetz/Celeb_glitzy') as chatbot:
16
  with gr.Row(scale=1):
17
  gr.Image("Cracked_Ball.jpg", show_label = False, show_share_button = False, show_download_button = False)
18
- gr.ChatInterface(magic_eight, type="messages", theme="mgetz/Celeb_glitzy", title="Spicy Magic 8-Ball")
 
19
  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 rude, brash, cruel chatbot"}]
 
9
 
10
+ if history:
11
+ messages.extend(history)
12
+
13
+ messages.append({"role": "user", "content": message})
14
+
15
+ response = client.chat_completion(
16
+ messages,
17
+ max_tokens=100
18
+ temperature=0.2
19
+ )
20
+ print(message)
21
+ print(history)
22
+
23
+ return response['choices'][0]['message']['content'].strip()
24
+
25
+ # def echo(message, history):
26
+ # return message
27
+
28
+ # def yes_no(message, history):
29
+ # responses = ["Yes", "No"]
30
+ # return random.choice(responses)
31
+
32
+ # def magic_eight(message, history):
33
+ # responses = ["That's a terrible question. Try again", "I don't think I should answer that...", "What do you think, genius?", "You are a bad person for asking that.", "Absolutely not", "Uuuuh, obviously.", "Of all the things you could ask, you went with that?", "I don't know, look it up", "I mean, yeah, I guess...", "That's gonna be a big nope", ""]
34
+ # return random.choice(responses)
35
 
36
  with gr.Blocks(theme='mgetz/Celeb_glitzy') as chatbot:
37
  with gr.Row(scale=1):
38
  gr.Image("Cracked_Ball.jpg", show_label = False, show_share_button = False, show_download_button = False)
39
+ gr.ChatInterface(respond, type="messages", theme="mgetz/Celeb_glitzy", title="Spicy Magic 8-Ball")
40
+
41
  chatbot.launch()