Spaces:
Sleeping
Sleeping
| import streamlit as st | |
| import os | |
| import random | |
| from generate_jokes import generate_inside_jokes, generate_motivation | |
| # Page Config | |
| st.set_page_config( | |
| page_title="Memory Forever", | |
| page_icon="π", | |
| layout="wide" | |
| ) | |
| # Custom CSS | |
| st.markdown(""" | |
| <style> | |
| .main { | |
| background-color: #f0f2f6; | |
| } | |
| .stButton>button { | |
| width: 100%; | |
| background-color: #ff4b4b; | |
| color: white; | |
| border-radius: 10px; | |
| height: 50px; | |
| font-size: 20px; | |
| } | |
| .joke-card { | |
| background-color: white; | |
| color: black; | |
| padding: 20px; | |
| border-radius: 10px; | |
| box-shadow: 0 4px 6px rgba(0,0,0,0.1); | |
| margin-bottom: 15px; | |
| border-left: 5px solid #ff4b4b; | |
| } | |
| .memory-card { | |
| background-color: #fff3cd; | |
| padding: 15px; | |
| border-radius: 10px; | |
| border: 1px solid #ffeeba; | |
| color: #856404; | |
| font-style: italic; | |
| } | |
| .motivation-card { | |
| background-color: #d4edda; | |
| color: #155724; | |
| padding: 20px; | |
| border-radius: 10px; | |
| border-left: 5px solid #28a745; | |
| margin-top: 20px; | |
| font-weight: bold; | |
| } | |
| h1 { | |
| color: #ff4b4b; | |
| text-align: center; | |
| font-family: 'Helvetica', sans-serif; | |
| } | |
| </style> | |
| """, unsafe_allow_html=True) | |
| # Header | |
| st.title("π Memory Forever π©ββοΈ") | |
| st.markdown("---") | |
| # Layout: 2 Columns | |
| col1, col2 = st.columns([1, 2]) | |
| with col1: | |
| st.header("πΈ Past Gallery") | |
| # Load images from 'sarah' directory | |
| image_dir = "sarah" | |
| if os.path.exists(image_dir): | |
| images = [f for f in os.listdir(image_dir) if f.lower().endswith(('.png', '.jpg', '.jpeg', '.gif'))] | |
| if images: | |
| # Display a random image or a grid | |
| selected_image = random.choice(images) | |
| st.image(os.path.join(image_dir, selected_image), caption="Classic Sarah Moment", use_container_width=True) | |
| # Optional: Show more images in an expander | |
| with st.expander("See more photos"): | |
| for img in images: | |
| st.image(os.path.join(image_dir, img), use_container_width=True) | |
| else: | |
| st.info("No images found in 'sarah' folder. Add some photos to see them here!") | |
| else: | |
| st.warning("Folder 'sarah' not found. Please create it and add images.") | |
| st.markdown("---") | |
| st.subheader("βοΈ Settings") | |
| count = st.slider("How many jokes?", 1, 10, 3) | |
| st.markdown("---") | |
| st.subheader("πͺ Daily Boost") | |
| if st.button("Need a quick motivation β¨"): | |
| with st.spinner("Finding the right words..."): | |
| motivation = generate_motivation() | |
| st.markdown(f'<div class="motivation-card">{motivation}</div>', unsafe_allow_html=True) | |
| with col2: | |
| st.header("β¨ Memory jokes fusion") | |
| if st.button("Generate π²"): | |
| with st.spinner("Cooking up some humor..."): | |
| try: | |
| jokes_text = generate_inside_jokes(count) | |
| # Parse the output to separate jokes and memory | |
| if "MEMORY FOR SARAH:" in jokes_text: | |
| parts = jokes_text.split("MEMORY FOR SARAH:") | |
| jokes_section = parts[0].replace("INSIDE JOKES:", "").strip() | |
| memory_section = parts[1].strip().strip('"') | |
| else: | |
| jokes_section = jokes_text | |
| memory_section = "Remember that time..." | |
| # Display Jokes | |
| st.markdown("### π Inside Jokes") | |
| for line in jokes_section.split('\n'): | |
| if line.strip(): | |
| st.markdown(f'<div class="joke-card">{line.strip()}</div>', unsafe_allow_html=True) | |
| # Display Memory | |
| st.markdown("### π A Memory to Cherish") | |
| st.markdown(f'<div class="memory-card">"{memory_section}"</div>', unsafe_allow_html=True) | |
| except Exception as e: | |
| st.error(f"Oof! Something went wrong: {e}") | |
| # Footer | |
| st.markdown("---") | |
| st.markdown("<div style='text-align: center; color: gray;'>Made with π by Aman</div>", unsafe_allow_html=True) | |