|
import gradio as gr |
|
import torch |
|
from transformers import pipeline |
|
|
|
|
|
model_id = "meta-llama/Llama-3.2-1B" |
|
pipe = pipeline( |
|
"text-generation", |
|
model=model_id, |
|
torch_dtype=torch.bfloat16, |
|
device_map="auto" |
|
) |
|
|
|
|
|
def generate_text(prompt): |
|
response = pipe(prompt, max_length=100, num_return_sequences=1) |
|
return response[0]['generated_text'] |
|
|
|
|
|
css = """ |
|
body {background-color: #f0f8ff; font-family: 'Arial', sans-serif;} |
|
.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);} |
|
textarea {border-radius: 10px; padding: 10px; font-size: 16px; border: 2px solid #ddd;} |
|
button {background-color: #4caf50; color: white; border-radius: 5px; padding: 10px 20px; font-size: 16px; border: none; cursor: pointer;} |
|
button:hover {background-color: #45a049;} |
|
h1 {color: #333; font-size: 32px; text-align: center;} |
|
footer {text-align: center; padding: 10px;} |
|
#icon {width: 50px; display: block; margin: 10px auto;} |
|
#prompt_box {padding: 10px; background-color: #f9f9f9; border-radius: 10px;} |
|
""" |
|
|
|
|
|
with gr.Blocks(css=css) as journal_app: |
|
|
|
|
|
gr.Image(value="https://cdn-icons-png.flaticon.com/512/2919/2919600.png", elem_id="icon", show_label=False) |
|
gr.Markdown("# π Productivity Journal") |
|
gr.Markdown("Welcome to your personalized productivity journal. Enter your thoughts and let AI inspire you to stay on track!") |
|
|
|
with gr.Row(): |
|
with gr.Column(): |
|
|
|
prompt = gr.Textbox(label="What's on your mind today? π", placeholder="Start writing your thoughts or goals...", elem_id="prompt_box", lines=5) |
|
|
|
with gr.Column(): |
|
|
|
output = gr.Textbox(label="Your AI Journal Entry β¨", lines=5) |
|
|
|
|
|
generate_button = gr.Button("Generate Entry βοΈ") |
|
|
|
|
|
generate_button.click(fn=generate_text, inputs=prompt, outputs=output) |
|
|
|
|
|
gr.Markdown("π Keep your spirits high and stay productive! π") |
|
gr.Markdown("Made with β€οΈ using Gradio and Llama-3.2") |
|
|
|
|
|
journal_app.launch() |
|
|