Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -3,62 +3,50 @@ import os
|
|
3 |
from huggingface_hub import login
|
4 |
from transformers import pipeline
|
5 |
|
6 |
-
#
|
7 |
-
|
8 |
-
|
9 |
-
# But no, it's just a model, much less spitting involved.
|
10 |
-
generator = pipeline('text-generation', model='meta-llama/Llama-3.1-8B-Instruct')
|
11 |
-
response = generator(message, max_length=150, num_return_sequences=1)
|
12 |
-
return response[0]['generated_text']
|
13 |
|
14 |
-
#
|
15 |
-
|
16 |
|
17 |
-
#
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
login_message = "Login failed. Perhaps the llama is on a coffee break. Try again?"
|
23 |
|
24 |
-
#
|
25 |
-
css
|
26 |
-
body {background-color: #f0f8ff; font-family: 'Comic Sans MS', cursive, sans-serif;}
|
27 |
-
.message {padding: 10px; margin: 5px; border-radius: 15px;}
|
28 |
-
.user-message {background: #e6f3ff; color: #0000FF;}
|
29 |
-
.llama-message {background: #ffe6e6; color: #FF0000; font-style: italic;}
|
30 |
-
#chatbot {border: 5px solid #d3d3d3; border-radius: 20px; background: url('data:image/svg+xml;utf8,<svg ...>'); background-size: cover;}
|
31 |
-
.button {background-color: #4CAF50; color: white; border: none; padding: 15px 32px; text-align: center; text-decoration: none; display: inline-block; font-size: 16px; margin: 4px 2px; cursor: pointer; transition: all 0.3s ease;}
|
32 |
-
.button:hover {background-color: #45a049; transform: scale(1.05);}
|
33 |
-
"""
|
34 |
-
|
35 |
-
with gr.Blocks(css=css, theme=gr.themes.Monochrome()) as demo:
|
36 |
-
gr.HTML("""
|
37 |
-
<div style="text-align: center; background: #add8e6; padding: 10px;">
|
38 |
-
<h1>🦙 Llama Chat 3000 - Where Wisdom Meets Wool</h1>
|
39 |
-
<img src="llama_logo.png" alt="Llama Logo" width="100">
|
40 |
-
</div>
|
41 |
-
""")
|
42 |
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
|
|
|
|
|
|
48 |
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
gr.Button("
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
#
|
63 |
-
|
64 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
3 |
from huggingface_hub import login
|
4 |
from transformers import pipeline
|
5 |
|
6 |
+
# Login using your Hugging Face API key
|
7 |
+
api_key = os.getenv("LLAMA")
|
8 |
+
login(api_key)
|
|
|
|
|
|
|
|
|
9 |
|
10 |
+
# Load the Llama model
|
11 |
+
llama_model = gr.load("models/meta-llama/Llama-3.1-8B-Instruct")
|
12 |
|
13 |
+
# Function to handle inputs and outputs
|
14 |
+
def chat_with_llama(user_input):
|
15 |
+
# Generate response using the pipeline
|
16 |
+
response = llama_model(user_input)
|
17 |
+
return response
|
|
|
18 |
|
19 |
+
# Customize Gradio interface
|
20 |
+
with gr.Blocks(css=".title {font-size: 3em; font-weight: bold; text-align: center; color: #4A90E2;}") as demo:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
21 |
|
22 |
+
# Header section
|
23 |
+
gr.Markdown(
|
24 |
+
"""
|
25 |
+
<div class="title">🦙 Llama 3.1 Chatbot 🦙</div>
|
26 |
+
<p style="text-align:center; font-size:1.2em; color:gray;">Ask anything from the advanced Llama 3.1 model!</p>
|
27 |
+
""",
|
28 |
+
elem_classes="header"
|
29 |
+
)
|
30 |
|
31 |
+
# Main input/output section
|
32 |
+
with gr.Row():
|
33 |
+
with gr.Column(scale=1):
|
34 |
+
user_input = gr.Textbox(label="Your question", placeholder="Type your question here...", lines=4)
|
35 |
+
with gr.Column(scale=1):
|
36 |
+
response_output = gr.Textbox(label="Llama's response", lines=4)
|
37 |
+
|
38 |
+
# Button to submit the input
|
39 |
+
submit_button = gr.Button("Submit", variant="primary")
|
40 |
+
|
41 |
+
# Link the input and output
|
42 |
+
submit_button.click(fn=chat_with_llama, inputs=user_input, outputs=response_output)
|
43 |
+
|
44 |
+
# Footer section
|
45 |
+
gr.Markdown(
|
46 |
+
"""
|
47 |
+
<div style="text-align:center; font-size:0.8em; color:gray;">Developed with ❤️ using Llama 3.1 and Gradio</div>
|
48 |
+
"""
|
49 |
+
)
|
50 |
+
|
51 |
+
# Launch the app
|
52 |
+
demo.launch()
|