Spaces:
Sleeping
Sleeping
| import gradio as gr | |
| from datetime import datetime | |
| import random | |
| # Romantic poems data | |
| romantic_poems = [ | |
| { | |
| "title": "Love's Eternal Flame", | |
| "text": "In the quiet moments between heartbeats,\nLove whispers secrets only souls can hear.\nThrough seasons of change, through nights of doubt,\nThis flame burns bright, never to fade away." | |
| }, | |
| { | |
| "title": "Sunrise of Love", | |
| "text": "Each morning I wake with your name on my lips,\nMy heart beats in rhythm with your heartbeat.\nIn your eyes I see tomorrow's promise,\nIn your smile I find my forever." | |
| }, | |
| { | |
| "title": "Heart's Symphony", | |
| "text": "Your love is the melody that plays in my soul,\nA symphony of joy, passion, and peace.\nWhen you're near, all worries fade away,\nLove's gentle touch makes everything complete." | |
| } | |
| ] | |
| # Love letter templates | |
| love_letters = [ | |
| { | |
| "title": "Dear My Beloved", | |
| "template": "My Dearest {name},\n\nEvery moment with you is a gift I treasure. Your smile brightens my darkest days, and your love fills my heart with joy. In this world of chaos, you are my calm.\n\nI love you more than words can express. You are my sunshine, my shelter, my everything.\n\nForever yours,\n{your_name}" | |
| }, | |
| { | |
| "title": "Love Letter to My Soul Mate", | |
| "template": "To the one who makes my heart sing,\n\nYou are not just my love, but my inspiration. With you, I am more than I ever dreamed I could be. Every day with you is a new adventure, and every moment feels like a dream come true.\n\nI cherish you, protect you, and love you beyond measure.\n\nYours always,\n{your_name}" | |
| } | |
| ] | |
| def generate_poem(prompt): | |
| # Simple poem generation based on prompt | |
| if not prompt: | |
| prompt = "love" | |
| selected_poem = random.choice(romantic_poems) | |
| return f"β¨ {selected_poem['title']} β¨\n\n{selected_poem['text']}" | |
| def generate_letter(name, your_name): | |
| if not name or not your_name: | |
| return "Please enter both names" | |
| selected_letter = random.choice(love_letters) | |
| letter = selected_letter["template"].format(name=name, your_name=your_name) | |
| return f"π {selected_letter['title']} π\n\n{letter}" | |
| def generate_love_message(): | |
| messages = [ | |
| "You are the reason I believe in magic.", | |
| "In your arms, I found my home.", | |
| "Every moment with you is a masterpiece.", | |
| "You make ordinary moments extraordinary.", | |
| "My heart beats only for you.", | |
| "Love is not about how many days you've been together, but how much you love each other.", | |
| "You are my today and all of my tomorrows.", | |
| "I love you to the moon and back.", | |
| "Every day with you is a blessing.", | |
| "You are the missing piece I never knew I was looking for." | |
| ] | |
| return random.choice(messages) | |
| # Global variable to track background index | |
| current_background_index = 0 | |
| with gr.Blocks( | |
| theme=gr.themes.Soft(), | |
| title="Stellar Verse - Romantic Poetry & Love Letters" | |
| ) as demo: | |
| # Header with beautiful styling | |
| gr.Markdown(""" | |
| <div style="text-align: center; padding: 20px;"> | |
| <h1 style="font-size: 3em; color: #ff69b4; font-family: 'Georgia', serif; margin-bottom: 10px;"> | |
| πΉ Stellar Verse πΉ | |
| </h1> | |
| <p style="font-size: 1.2em; color: #8b4513; font-family: 'Georgia', serif;"> | |
| Where Love Finds Its Voice & Hearts Find Their Song | |
| </p> | |
| </div> | |
| """) | |
| with gr.Tabs(): | |
| # Tab 1: Romantic Poems | |
| with gr.Tab("β¨ Romantic Poems"): | |
| gr.Markdown("### Crafted for Your Heart's Desire") | |
| with gr.Row(): | |
| with gr.Column(scale=2): | |
| poem_prompt = gr.Textbox( | |
| label="What kind of love do you seek?", | |
| placeholder="Love, heartbreak, eternity, passion, romance...", | |
| lines=3 | |
| ) | |
| poem_btn = gr.Button("β¨ Generate Romantic Poem", variant="primary") | |
| with gr.Column(scale=1): | |
| time_display = gr.Textbox( | |
| label="Current Time", | |
| interactive=False, | |
| value="Loading..." | |
| ) | |
| with gr.Row(): | |
| poem_output = gr.Textbox( | |
| label="Your Personalized Poem", | |
| lines=10, | |
| interactive=False, | |
| show_copy_button=True | |
| ) | |
| # Tab 2: Love Letters | |
| with gr.Tab("π Love Letters"): | |
| gr.Markdown("### Express Your Heart in Beautiful Words") | |
| with gr.Row(): | |
| with gr.Column(): | |
| name_input = gr.Textbox(label="Recipient's Name", placeholder="Enter the name of your beloved") | |
| your_name_input = gr.Textbox(label="Your Name", placeholder="Enter your name") | |
| letter_btn = gr.Button("π Create Love Letter", variant="secondary") | |
| with gr.Column(): | |
| letter_output = gr.Textbox( | |
| label="Your Beautiful Letter", | |
| lines=10, | |
| interactive=False, | |
| show_copy_button=True | |
| ) | |
| # Tab 3: Love Messages | |
| with gr.Tab("π Love Messages"): | |
| gr.Markdown("### Short & Sweet Expressions of Love") | |
| with gr.Row(): | |
| message_btn = gr.Button("β¨ Generate Love Message", variant="primary") | |
| message_output = gr.Textbox( | |
| label="Your Love Message", | |
| interactive=False, | |
| lines=3, | |
| show_copy_button=True | |
| ) | |
| # Event handling | |
| def update_poem(prompt): | |
| return generate_poem(prompt) | |
| def update_letter(name, your_name): | |
| return generate_letter(name, your_name) | |
| def update_message(): | |
| return generate_love_message() | |
| # Connect events | |
| poem_btn.click( | |
| fn=update_poem, | |
| inputs=[poem_prompt], | |
| outputs=[poem_output] | |
| ) | |
| letter_btn.click( | |
| fn=update_letter, | |
| inputs=[name_input, your_name_input], | |
| outputs=[letter_output] | |
| ) | |
| message_btn.click( | |
| fn=update_message, | |
| inputs=[], | |
| outputs=[message_output] | |
| ) | |
| # Launch the app | |
| if __name__ == "__main__": | |
| demo.launch() | |