Spaces:
Sleeping
Sleeping
connected chatbot to LLM
Browse files
app.py
CHANGED
|
@@ -2,6 +2,19 @@ import gradio as gr
|
|
| 2 |
import random
|
| 3 |
#import lines fo at the top! Any libraries I need to import go here
|
| 4 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 5 |
def magic_8_ball(message, history):
|
| 6 |
return random.choice(['Yes', "No","Try again", "Definitely", "Most likely not", "Without a doubt"])
|
| 7 |
|
|
@@ -13,7 +26,7 @@ def magic_8_ball(message, history):
|
|
| 13 |
#a function that the user's message is repeated back to you
|
| 14 |
|
| 15 |
print("Hello World")
|
| 16 |
-
chatbot = gr.ChatInterface(
|
| 17 |
#defining my chatbot so that the user can interact and see their conversation history and send me messages
|
| 18 |
|
| 19 |
chatbot.launch()
|
|
|
|
| 2 |
import random
|
| 3 |
#import lines fo at the top! Any libraries I need to import go here
|
| 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 |
+
#system message
|
| 10 |
+
if history:
|
| 11 |
+
messages.extend(history)
|
| 12 |
+
messages.append({"role": "user", "content": message})
|
| 13 |
+
#user message
|
| 14 |
+
response = client.chat_completion(messages, max_tokens = 100)
|
| 15 |
+
#max_tokens caps the number od letters in the return message
|
| 16 |
+
return response['choices'][0]['message']["content"].strip()
|
| 17 |
+
|
| 18 |
def magic_8_ball(message, history):
|
| 19 |
return random.choice(['Yes', "No","Try again", "Definitely", "Most likely not", "Without a doubt"])
|
| 20 |
|
|
|
|
| 26 |
#a function that the user's message is repeated back to you
|
| 27 |
|
| 28 |
print("Hello World")
|
| 29 |
+
chatbot = gr.ChatInterface(respond, type="messages", title="Magic 8 Ball", description="I will answer all of your questions about the future! Matt's ex: https://huggingface.co/spaces/mgetz/SanFran/blob/main/app.py")
|
| 30 |
#defining my chatbot so that the user can interact and see their conversation history and send me messages
|
| 31 |
|
| 32 |
chatbot.launch()
|