Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,60 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import torch
|
3 |
+
from transformers import pipeline
|
4 |
+
|
5 |
+
# Set up the model
|
6 |
+
model_id = "meta-llama/Llama-3.2-1B"
|
7 |
+
pipe = pipeline(
|
8 |
+
"text-generation",
|
9 |
+
model=model_id,
|
10 |
+
torch_dtype=torch.bfloat16,
|
11 |
+
device_map="auto"
|
12 |
+
)
|
13 |
+
|
14 |
+
# Text generation function
|
15 |
+
def generate_text(prompt):
|
16 |
+
response = pipe(prompt, max_length=100, num_return_sequences=1)
|
17 |
+
return response[0]['generated_text']
|
18 |
+
|
19 |
+
# Custom CSS for the app
|
20 |
+
css = """
|
21 |
+
body {background-color: #f0f8ff; font-family: 'Arial', sans-serif;}
|
22 |
+
.gradio-container {max-width: 700px; margin: 0 auto; border-radius: 15px; padding: 20px; background-color: white; box-shadow: 0 4px 8px rgba(0,0,0,0.1);}
|
23 |
+
textarea {border-radius: 10px; padding: 10px; font-size: 16px; border: 2px solid #ddd;}
|
24 |
+
button {background-color: #4caf50; color: white; border-radius: 5px; padding: 10px 20px; font-size: 16px; border: none; cursor: pointer;}
|
25 |
+
button:hover {background-color: #45a049;}
|
26 |
+
h1 {color: #333; font-size: 32px; text-align: center;}
|
27 |
+
footer {text-align: center; padding: 10px;}
|
28 |
+
#icon {width: 50px; display: block; margin: 10px auto;}
|
29 |
+
#prompt_box {padding: 10px; background-color: #f9f9f9; border-radius: 10px;}
|
30 |
+
"""
|
31 |
+
|
32 |
+
# Create the Gradio interface
|
33 |
+
with gr.Blocks(css=css) as journal_app:
|
34 |
+
|
35 |
+
# Header and icons
|
36 |
+
gr.Image(value="https://cdn-icons-png.flaticon.com/512/2919/2919600.png", elem_id="icon", show_label=False)
|
37 |
+
gr.Markdown("# π Productivity Journal")
|
38 |
+
gr.Markdown("Welcome to your personalized productivity journal. Enter your thoughts and let AI inspire you to stay on track!")
|
39 |
+
|
40 |
+
with gr.Row():
|
41 |
+
with gr.Column():
|
42 |
+
# Input text box
|
43 |
+
prompt = gr.Textbox(label="What's on your mind today? π", placeholder="Start writing your thoughts or goals...", elem_id="prompt_box", lines=5)
|
44 |
+
|
45 |
+
with gr.Column():
|
46 |
+
# Output for generated text
|
47 |
+
output = gr.Textbox(label="Your AI Journal Entry β¨", lines=5)
|
48 |
+
|
49 |
+
# Generate button
|
50 |
+
generate_button = gr.Button("Generate Entry βοΈ")
|
51 |
+
|
52 |
+
# Define the click event
|
53 |
+
generate_button.click(fn=generate_text, inputs=prompt, outputs=output)
|
54 |
+
|
55 |
+
# Footer
|
56 |
+
gr.Markdown("π Keep your spirits high and stay productive! π")
|
57 |
+
gr.Markdown("Made with β€οΈ using Gradio and Llama-3.2")
|
58 |
+
|
59 |
+
# Launch the app
|
60 |
+
journal_app.launch()
|