initial commit
Browse files- README.md +2 -1
- app.py +57 -54
- requirements.txt +1 -1
README.md
CHANGED
|
@@ -1,5 +1,5 @@
|
|
| 1 |
---
|
| 2 |
-
title:
|
| 3 |
emoji: 💬
|
| 4 |
colorFrom: yellow
|
| 5 |
colorTo: purple
|
|
@@ -7,6 +7,7 @@ sdk: gradio
|
|
| 7 |
sdk_version: 5.0.1
|
| 8 |
app_file: app.py
|
| 9 |
pinned: false
|
|
|
|
| 10 |
---
|
| 11 |
|
| 12 |
An example chatbot using [Gradio](https://gradio.app), [`huggingface_hub`](https://huggingface.co/docs/huggingface_hub/v0.22.2/en/index), and the [Hugging Face Inference API](https://huggingface.co/docs/api-inference/index).
|
|
|
|
| 1 |
---
|
| 2 |
+
title: Buttler7
|
| 3 |
emoji: 💬
|
| 4 |
colorFrom: yellow
|
| 5 |
colorTo: purple
|
|
|
|
| 7 |
sdk_version: 5.0.1
|
| 8 |
app_file: app.py
|
| 9 |
pinned: false
|
| 10 |
+
license: mit
|
| 11 |
---
|
| 12 |
|
| 13 |
An example chatbot using [Gradio](https://gradio.app), [`huggingface_hub`](https://huggingface.co/docs/huggingface_hub/v0.22.2/en/index), and the [Hugging Face Inference API](https://huggingface.co/docs/api-inference/index).
|
app.py
CHANGED
|
@@ -1,64 +1,67 @@
|
|
| 1 |
-
|
| 2 |
-
|
| 3 |
-
|
| 4 |
-
|
| 5 |
-
For more information on `huggingface_hub` Inference API support, please check the docs: https://huggingface.co/docs/huggingface_hub/v0.22.2/en/guides/inference
|
| 6 |
-
"""
|
| 7 |
-
client = InferenceClient("HuggingFaceH4/zephyr-7b-beta")
|
| 8 |
-
|
| 9 |
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
system_message,
|
| 14 |
-
max_tokens,
|
| 15 |
-
temperature,
|
| 16 |
-
top_p,
|
| 17 |
-
):
|
| 18 |
-
messages = [{"role": "system", "content": system_message}]
|
| 19 |
-
|
| 20 |
-
for val in history:
|
| 21 |
-
if val[0]:
|
| 22 |
-
messages.append({"role": "user", "content": val[0]})
|
| 23 |
-
if val[1]:
|
| 24 |
-
messages.append({"role": "assistant", "content": val[1]})
|
| 25 |
|
| 26 |
-
|
|
|
|
| 27 |
|
| 28 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 29 |
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
temperature=temperature,
|
| 35 |
-
top_p=top_p,
|
| 36 |
-
):
|
| 37 |
-
token = message.choices[0].delta.content
|
| 38 |
|
| 39 |
-
|
| 40 |
-
|
|
|
|
|
|
|
| 41 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 42 |
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
value=0.95,
|
| 56 |
-
step=0.05,
|
| 57 |
-
label="Top-p (nucleus sampling)",
|
| 58 |
-
),
|
| 59 |
-
],
|
| 60 |
-
)
|
| 61 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 62 |
|
|
|
|
| 63 |
if __name__ == "__main__":
|
| 64 |
-
demo.launch()
|
|
|
|
| 1 |
+
# This Gradio app simulates a smart assistant similar to Alexa, but with the capabilities of LLaMA 3.2.
|
| 2 |
+
# The assistant listens for the wake word "Hey Butler" and responds to user commands.
|
| 3 |
+
# It can also sync with Bluetooth devices and perform tasks based on user input.
|
| 4 |
+
# The assistant can be trained after each conversation to improve its responses.
|
|
|
|
|
|
|
|
|
|
|
|
|
| 5 |
|
| 6 |
+
import gradio as gr
|
| 7 |
+
import numpy as np
|
| 8 |
+
import transformers_js_py # Assuming this is a fictional library for LLaMA 3.2
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 9 |
|
| 10 |
+
# Initialize the LLaMA 3.2 model
|
| 11 |
+
model = transformers_js_py.LLaMA32Model()
|
| 12 |
|
| 13 |
+
# Function to simulate the assistant's response
|
| 14 |
+
def assistant_response(user_input, history):
|
| 15 |
+
# Check if the wake word is present
|
| 16 |
+
if "Hey Butler" in user_input:
|
| 17 |
+
# Generate a response using the LLaMA 3.2 model
|
| 18 |
+
response = model.generate_response(user_input, history)
|
| 19 |
+
# Simulate Bluetooth sync
|
| 20 |
+
sync_bluetooth()
|
| 21 |
+
return response
|
| 22 |
+
else:
|
| 23 |
+
return "Please say 'Hey Butler' to activate the assistant."
|
| 24 |
|
| 25 |
+
# Function to simulate Bluetooth sync
|
| 26 |
+
def sync_bluetooth():
|
| 27 |
+
# Simulate Bluetooth sync (this is a placeholder function)
|
| 28 |
+
print("Bluetooth synced successfully.")
|
|
|
|
|
|
|
|
|
|
|
|
|
| 29 |
|
| 30 |
+
# Function to train the model after each conversation
|
| 31 |
+
def train_model(user_input, assistant_response, history):
|
| 32 |
+
# Train the model with the new conversation data
|
| 33 |
+
model.train(user_input, assistant_response, history)
|
| 34 |
|
| 35 |
+
# Define the Gradio interface
|
| 36 |
+
with gr.Blocks() as demo:
|
| 37 |
+
# Create a chatbot component
|
| 38 |
+
chatbot = gr.Chatbot(type="messages")
|
| 39 |
+
# Create a textbox for user input
|
| 40 |
+
user_input = gr.Textbox(label="User Input")
|
| 41 |
+
# Create a button to clear the chat history
|
| 42 |
+
clear_button = gr.Button("Clear History")
|
| 43 |
|
| 44 |
+
# Define the event listener for user input
|
| 45 |
+
user_input.submit(
|
| 46 |
+
assistant_response,
|
| 47 |
+
inputs=[user_input, chatbot],
|
| 48 |
+
outputs=[chatbot],
|
| 49 |
+
queue=False
|
| 50 |
+
).then(
|
| 51 |
+
train_model,
|
| 52 |
+
inputs=[user_input, chatbot, chatbot],
|
| 53 |
+
outputs=None,
|
| 54 |
+
queue=False
|
| 55 |
+
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 56 |
|
| 57 |
+
# Define the event listener for the clear button
|
| 58 |
+
clear_button.click(
|
| 59 |
+
lambda: None,
|
| 60 |
+
None,
|
| 61 |
+
chatbot,
|
| 62 |
+
queue=False
|
| 63 |
+
)
|
| 64 |
|
| 65 |
+
# Launch the Gradio app
|
| 66 |
if __name__ == "__main__":
|
| 67 |
+
demo.launch(show_error=True)
|
requirements.txt
CHANGED
|
@@ -1 +1 @@
|
|
| 1 |
-
|
|
|
|
| 1 |
+
numpy
|