Spaces:
Sleeping
Sleeping
Added token and connected inference client
Browse files
app.py
CHANGED
|
@@ -1,12 +1,26 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
import random
|
|
|
|
|
|
|
|
|
|
| 3 |
|
| 4 |
def random_message(message, history):
|
| 5 |
choices = ["yes", "no"]
|
| 6 |
-
#use random to select one of those choices
|
| 7 |
chat_answer = random.choice(choices)
|
| 8 |
return chat_answer
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 9 |
|
| 10 |
-
chatbot = gr.ChatInterface(
|
| 11 |
|
| 12 |
chatbot.launch()
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
import random
|
| 3 |
+
import InferenceClient
|
| 4 |
+
|
| 5 |
+
client = InferenceClient("HuggingFaceH4/zephyr-7b-beta")
|
| 6 |
|
| 7 |
def random_message(message, history):
|
| 8 |
choices = ["yes", "no"]
|
| 9 |
+
# use random to select one of those choices
|
| 10 |
chat_answer = random.choice(choices)
|
| 11 |
return chat_answer
|
| 12 |
+
|
| 13 |
+
def respond(message, history):
|
| 14 |
+
messages = [{"role": "system", "content": "You are a friendly chatbot."}]
|
| 15 |
+
if history:
|
| 16 |
+
messages.extend(history)
|
| 17 |
+
|
| 18 |
+
messages.append({"role": "user", "content" : message})
|
| 19 |
+
|
| 20 |
+
response = client.chat_completion(messages, max_tokens=100)
|
| 21 |
+
return response["choices"][0]["message"]["content"].strip()
|
| 22 |
+
|
| 23 |
|
| 24 |
+
chatbot = gr.ChatInterface(respond, type = "messages", title = "ChatBot for KWK")
|
| 25 |
|
| 26 |
chatbot.launch()
|