File size: 3,713 Bytes
94fd294
601a3ba
 
 
 
 
48521c3
601a3ba
 
 
 
18de9c1
601a3ba
 
18de9c1
601a3ba
 
 
 
 
 
 
cd40814
 
 
601a3ba
cd40814
 
 
 
601a3ba
 
1fc0910
 
 
 
 
 
 
 
 
3096487
 
 
 
601a3ba
 
 
691ff52
601a3ba
691ff52
 
cd40814
 
601a3ba
cd40814
691ff52
3096487
140fb0a
601a3ba
cd40814
 
 
 
 
 
 
 
601a3ba
 
 
 
691ff52
 
601a3ba
 
 
 
 
 
3096487
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
import spaces
import gradio as gr
import torch
from transformers import pipeline

# Set up the model
model_id = "meta-llama/Llama-3.2-3B"
pipe = pipeline(
    "text-generation", 
    model=model_id, 
    torch_dtype=torch.bfloat16, 
    device_map="cuda"
)

@spaces.GPU
def generate_text(prompt):
    response = pipe(prompt, max_length=100, num_return_sequences=1)
    return response[0]['generated_text']

# Custom CSS for the app
css = """
body {background-color: #f0f8ff; font-family: 'Arial', sans-serif;}
.gradio-container {max-width: 900px; margin: 0 auto; border-radius: 15px; padding: 30px; background-color: white; box-shadow: 0 4px 8px rgba(0,0,0,0.1);}
textarea {border-radius: 10px; padding: 15px; font-size: 16px; border: 2px solid #ddd; width: 100%;}
button {background-color: #4caf50; color: white; border-radius: 10px; padding: 10px 15px; font-size: 16px; border: none; cursor: pointer; margin-top: 10px; margin-right: 5px;}
button:hover {background-color: #45a049;}
h1 {color: #333; font-size: 36px; text-align: center; margin-bottom: 20px;}
h2 {color: #555; font-size: 24px; margin-bottom: 10px;}
footer {text-align: center; padding: 20px; font-size: 14px;}
.grid {display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; justify-items: stretch;}
"""

# Define example entries
example_entries = [
    "Today, I finished a major project that I’ve been working on for weeks. It felt great to finally get it done, and I’m proud of the effort I put in.",
    "I faced a tough challenge today when I had to give a presentation with very little preparation. Despite feeling nervous, I managed to pull through by staying calm and focused.",
    "Tomorrow, my goal is to focus on improving my communication skills during team meetings. I want to make sure I’m clear and concise in expressing my ideas.",
    "I’m grateful for the support I received from my coworkers today. Their encouragement really helped me push through a stressful moment.",
    "I learned a new approach to managing my time more effectively today. I’m going to apply this to my daily routine to see if it helps me stay more productive."
]

# Function to return the selected prompt
def fill_prompt(selected_prompt):
    return gr.update(value=selected_prompt)

# Create the Gradio interface
with gr.Blocks(css=css) as journal_app:
    
    # Header and introduction
    gr.Markdown("# 📝 Productivity Journal")
    gr.Markdown("Welcome to your personalized productivity journal. Click an example below or write your thoughts!")

    # Example journal entries section
    gr.Markdown("### **Select an example to start writing:**")
    
    # Align buttons in grid format for better layout
    with gr.Row():
        prompt_textbox = gr.Textbox(label="Write your thoughts here:", placeholder="Start writing or select an example...", elem_id="prompt_box", lines=5)

        with gr.Column():
            # Arrange example buttons in grid format
            with gr.Box(elem_classes="grid"):
                for i, entry in enumerate(example_entries):
                    gr.Button(f"Example {i+1}").click(fn=lambda e=entry: fill_prompt(e), inputs=None, outputs=prompt_textbox)
    
    with gr.Row():
        # Output for generated text
        output = gr.Textbox(label="Your AI Journal Entry ✨", lines=6)
    
    # Generate button
    generate_button = gr.Button("Generate Entry ✍️")

    # Define the click event for text generation
    generate_button.click(fn=generate_text, inputs=prompt_textbox, outputs=output)

    # Footer
    gr.Markdown("🌞 Keep your spirits high and stay productive! 😊")
    gr.Markdown("Made with ❤️ using Gradio and Llama-3.2")

# Launch the app
journal_app.launch()