snehagarg170 commited on
Commit
2c4f91c
·
verified ·
1 Parent(s): a0a9739

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -12
app.py CHANGED
@@ -1,15 +1,18 @@
1
- #importing gradio
2
  import gradio as gr
3
- #import libraries here
4
  import random
5
-
6
- #giving chatbot a function
7
- def yes_or_no(message, history):
8
- return random.choice(['yes','no'])
9
-
10
- #defining my chatbot for user to interact and see their conversation history and send new messages
11
- print("hello!")
12
- chatbot = gr.ChatInterface(yes_or_no, type="messages")
13
-
14
- #launching chatbot
 
 
 
 
 
15
  chatbot.launch()
 
 
1
  import gradio as gr
 
2
  import random
3
+ from huggingface_hub import InferenceClient
4
+ client = InferenceClient(“HuggingFaceH4/zephyr-7b-beta”)
5
+ def respond(message, history):
6
+ messages = [{“role”: “system”, “content”: “You are a friendly chatbot.“}]
7
+ if history:
8
+ messages.extend(history)
9
+ messages.append({“role”: “user”, “content”: message})
10
+ response = client.chat_completion(messages, max_tokens = 100)
11
+ return response[‘choices’][0][‘message’][‘content’].strip()
12
+ def echo(message, history):
13
+ return message
14
+ def yes_no(message, history):
15
+ responses = [“Yes”, “No”]
16
+ return random.choice(responses)
17
+ chatbot = gr.ChatInterface(respond, type=“messages”)
18
  chatbot.launch()