Spaces:
Sleeping
Sleeping
Made LLM
#1
by anniesaxena - opened
app.py
CHANGED
|
@@ -1,5 +1,9 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
import random
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3 |
|
| 4 |
#def respond_yes_no_random(message, history):
|
| 5 |
# responses = ["yes", "no"]
|
|
@@ -7,11 +11,24 @@ import random
|
|
| 7 |
|
| 8 |
#chatbot = gr.ChatInterface(respond_yes_no_random, type = "messages", examples = ["HELLO", "Bye!"], title = "Annie's ChatBot")
|
| 9 |
|
| 10 |
-
def
|
| 11 |
-
|
| 12 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 13 |
|
| 14 |
-
chatbot = gr.ChatInterface(
|
| 15 |
|
| 16 |
chatbot.launch()
|
| 17 |
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
import random
|
| 3 |
+
import os
|
| 4 |
+
from huggingface_hub import InferenceClient
|
| 5 |
+
|
| 6 |
+
client = InferenceClient("HuggingFaceH4/zephyr-7b-beta")
|
| 7 |
|
| 8 |
#def respond_yes_no_random(message, history):
|
| 9 |
# responses = ["yes", "no"]
|
|
|
|
| 11 |
|
| 12 |
#chatbot = gr.ChatInterface(respond_yes_no_random, type = "messages", examples = ["HELLO", "Bye!"], title = "Annie's ChatBot")
|
| 13 |
|
| 14 |
+
def respond(message, history):
|
| 15 |
+
messages = [{"role": "system", "content": "You are a vampire!"}]
|
| 16 |
+
|
| 17 |
+
if history:
|
| 18 |
+
messages.extend(history)
|
| 19 |
+
|
| 20 |
+
messages.append({"role":"user","content": message"})
|
| 21 |
+
|
| 22 |
+
response = client.chat_completion(
|
| 23 |
+
messages,
|
| 24 |
+
max_tokens=100
|
| 25 |
+
)
|
| 26 |
+
|
| 27 |
+
return response['choice'][0]['message']['content'].strip()
|
| 28 |
+
|
| 29 |
+
|
| 30 |
|
| 31 |
+
chatbot = gr.ChatInterface(respond, type = "messages")
|
| 32 |
|
| 33 |
chatbot.launch()
|
| 34 |
|