David1717 commited on
Commit
43d18d9
·
verified ·
1 Parent(s): 2f7fec9

initial commit

Browse files
Files changed (3) hide show
  1. README.md +2 -1
  2. app.py +57 -54
  3. requirements.txt +1 -1
README.md CHANGED
@@ -1,5 +1,5 @@
1
  ---
2
- title: Gradio Chatbot
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
- import gradio as gr
2
- from huggingface_hub import InferenceClient
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
- def respond(
11
- message,
12
- history: list[tuple[str, str]],
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
- messages.append({"role": "user", "content": message})
 
27
 
28
- response = ""
 
 
 
 
 
 
 
 
 
 
29
 
30
- for message in client.chat_completion(
31
- messages,
32
- max_tokens=max_tokens,
33
- stream=True,
34
- temperature=temperature,
35
- top_p=top_p,
36
- ):
37
- token = message.choices[0].delta.content
38
 
39
- response += token
40
- yield response
 
 
41
 
 
 
 
 
 
 
 
 
42
 
43
- """
44
- For information on how to customize the ChatInterface, peruse the gradio docs: https://www.gradio.app/docs/chatinterface
45
- """
46
- demo = gr.ChatInterface(
47
- respond,
48
- additional_inputs=[
49
- gr.Textbox(value="You are a friendly Chatbot.", label="System message"),
50
- gr.Slider(minimum=1, maximum=2048, value=512, step=1, label="Max new tokens"),
51
- gr.Slider(minimum=0.1, maximum=4.0, value=0.7, step=0.1, label="Temperature"),
52
- gr.Slider(
53
- minimum=0.1,
54
- maximum=1.0,
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
- huggingface_hub==0.25.2
 
1
+ numpy