Spaces:
Sleeping
Sleeping
NewApp.py
Browse files
app.py
CHANGED
|
@@ -1,18 +1,32 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
import random
|
|
|
|
| 3 |
|
| 4 |
-
|
| 5 |
-
# return (message)
|
| 6 |
|
| 7 |
-
# def yesNoRandom(message,history):
|
| 8 |
-
# repsonse=["yes","no"]
|
| 9 |
-
# return random.choice(repsonse)
|
| 10 |
|
| 11 |
-
# chatbot = gr.ChatInterface(yesNoRandom, type = "messages", title = "Yes or No Bot", description = "This chatbot randomly repsonds to questions with yes or no.")
|
| 12 |
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 17 |
|
| 18 |
-
chatbot.launch()
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
import random
|
| 3 |
+
import os
|
| 4 |
|
| 5 |
+
from huggingface_hub import InferenceClient
|
|
|
|
| 6 |
|
|
|
|
|
|
|
|
|
|
| 7 |
|
|
|
|
| 8 |
|
| 9 |
+
client = InferenceClient("HuggingFaceH4/zephyr-7b-beta")
|
| 10 |
+
|
| 11 |
+
|
| 12 |
+
def respond(message,history):
|
| 13 |
+
messages = [{"role":"system","You are a friendly chatbot!"}]
|
| 14 |
+
|
| 15 |
+
if history:
|
| 16 |
+
messages.extend(history)
|
| 17 |
+
messages.append({"role":"user","content":messages})
|
| 18 |
+
|
| 19 |
+
response = client.chat_completion(
|
| 20 |
+
mesages,
|
| 21 |
+
max_token=100)
|
| 22 |
+
return response ['choices'][0]['message']['content'].strip()
|
| 23 |
+
|
| 24 |
+
|
| 25 |
+
|
| 26 |
+
|
| 27 |
+
chatbot = gr.ChatInterface(repsond, type = "messages")
|
| 28 |
+
|
| 29 |
+
chatbot.launch()
|
| 30 |
+
|
| 31 |
+
|
| 32 |
|
|
|