import streamlit as st import google.generativeai as genai import re import os # Set up page st.set_page_config( page_title="LinkedIn Post Generator", page_icon="🚀", layout="centered", initial_sidebar_state="collapsed" ) # Modern CSS styling st.markdown(""" """, unsafe_allow_html=True) # Header section st.markdown('

LinkedIn Post Generator

Create viral professional posts from your learning journey

', unsafe_allow_html=True) # Input card with st.form("input_form"): st.markdown('
', unsafe_allow_html=True) goal = st.text_input("🎯 Your Career Goal", placeholder="e.g., Become a Full-Stack Developer") day_number = st.text_input("📆 Day Number", placeholder="e.g., Day 42") topics = st.text_area("📚 Topics Learned Today (Separate with commas)", placeholder="e.g., Python decorators, API design, Data visualization", height=100) st.markdown('
', unsafe_allow_html=True) submitted = st.form_submit_button("✨ Generate Post", use_container_width=True) # Process topics topics_list = [t.strip() for t in topics.split(',') if t.strip()] if topics else [] # Display topics as pills if topics_list: st.markdown("### Today's Topics") pills_html = "".join([f'{topic}' for topic in topics_list]) st.markdown(pills_html, unsafe_allow_html=True) # Gemini API setup api_key = os.getenv("GEMINI_API_KEY") or "AIzaSyCWxM6Ic9zs-hZiovnMU8a4UJko7ObqPqU" # Generate post on submit if submitted: if not all([goal, day_number, topics_list]): st.warning("Please fill all fields!") st.stop() try: genai.configure(api_key=api_key) model = genai.GenerativeModel('gemini-1.5-flash') prompt = f""" You are a LinkedIn content expert helping create viral professional posts for tech learners. Create an engaging LinkedIn post with these elements: 1. Catchy hook that grabs attention 2. Professional tone with 1-2 relevant emojis 3. Show learning journey progress 4. Value-packed insights from topics 5. Curiosity-sparking question for engagement 6. Relevant hashtags (5-7) 7. Format: Clear paragraphs, no markdown Context: - Career Goal: {goal} - Learning Day: {day_number} - Topics: {", ".join(topics_list)} """ with st.spinner("🚀 Crafting your viral post..."): response = model.generate_content(prompt) post = response.text # Post-processing post = re.sub(r'\*\*(.*?)\*\*', r'\1', post) # Bold formatting post = post.replace('•', '◉') # Better bullet points # Display result st.markdown(f"""

Your Viral LinkedIn Post

{post}
""", unsafe_allow_html=True) # Copy button st.code(post, language="text") except Exception as e: st.error(f"Error generating post: {str(e)}") # Empty state illustration elif not submitted: st.markdown("""

Fill in your learning details

Enter your goal, day number, and topics to generate a viral LinkedIn post

""", unsafe_allow_html=True)