Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,31 +1,24 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
import random
|
| 3 |
-
from huggingface_hub import InferenceClient
|
| 4 |
|
| 5 |
-
client = InferenceClient(
|
| 6 |
|
| 7 |
def respond(message, history):
|
| 8 |
-
messages[{
|
| 9 |
-
|
| 10 |
if history:
|
| 11 |
messages.extend(history)
|
|
|
|
|
|
|
|
|
|
| 12 |
|
| 13 |
-
messages.append({"role": "user", "content": message})
|
| 14 |
-
|
| 15 |
-
response = client.chat_completion(messages, max_token = 100)
|
| 16 |
-
|
| 17 |
-
return response['choices'][0]['message']['content'].strip()
|
| 18 |
-
|
| 19 |
-
#def magic_8_ball(message, history):
|
| 20 |
-
#return random.choice(['yes', 'no', 'maybe'])
|
| 21 |
-
|
| 22 |
-
def yes_or_no(message, history):
|
| 23 |
-
return random.choice(['Yes', 'No'])
|
| 24 |
def echo(message, history):
|
| 25 |
return message
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
|
|
|
| 31 |
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 friendly chatbot.“}]
|
| 9 |
+
|
| 10 |
if history:
|
| 11 |
messages.extend(history)
|
| 12 |
+
messages.append({“role”: “user”, “content”: message})
|
| 13 |
+
response = client.chat_completion(messages, max_tokens = 100)
|
| 14 |
+
return response[‘choices’][0][‘message’][‘content’].strip()
|
| 15 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 16 |
def echo(message, history):
|
| 17 |
return message
|
| 18 |
+
|
| 19 |
+
def yes_no(message, history):
|
| 20 |
+
responses = [“Yes”, “No”]
|
| 21 |
+
return random.choice(responses)
|
| 22 |
+
|
| 23 |
+
chatbot = gr.ChatInterface(respond, type=“messages”)
|
| 24 |
chatbot.launch()
|