matchalover commited on
Commit
7921c8a
·
verified ·
1 Parent(s): a21567f

adding huggingface & transitioning to a generative AI model

Browse files
Files changed (1) hide show
  1. app.py +19 -5
app.py CHANGED
@@ -1,9 +1,23 @@
1
  import gradio as gr
2
- import random
3
 
4
- def magic_chatbot(message, history):
5
- magic_8 = ["Yes", "No", "Don't know"]
6
- return random.choices(magic_8)
 
 
 
 
 
 
 
 
 
 
 
 
 
7
 
8
- chatbot = gr.ChatInterface(magic_chatbot, type='messages', title="Magic 8 Ball", description = "Ask me your most pressing question!")
 
9
  chatbot.launch()
 
1
  import gradio as gr
2
+ from huggingface_hub import InferenceClient
3
 
4
+ client = InferenceClient("HuggingFaceH4/zephyr-7b-beta")
5
+
6
+ def respond(message, history):
7
+ messages =[{"role": "system", "content": "You're a friendly chatbot"}] #dictionary
8
+
9
+ if history:
10
+ messages.extend(history)
11
+
12
+ messages.append({"role": "user", "content": message}) # conditional bc we might not have history
13
+
14
+ response = client.chat_completion(
15
+ messages # list of dicitonaries containing all the messages
16
+ max_tokens=100
17
+ temperature=0.2
18
+ )
19
+ return response["choices"][0]['message']['content'].strip()
20
 
21
+ chatbot = gr.ChatInterface(magic_chatbot, type='messages')
22
+
23
  chatbot.launch()