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)
# New remarks section
remarks = st.text_area("💡 Remarks (Optional)",
placeholder="e.g., Created project notes, Built a mini-application, Solved 5 Leetcode problems",
height=100,
help="Additional learning activities you did today")
st.markdown('
', unsafe_allow_html=True)
submitted = st.form_submit_button("✨ Generate Post", use_container_width=True)
# Process inputs
topics_list = [t.strip() for t in topics.split(',') if t.strip()] if topics else []
remarks_list = [r.strip() for r in remarks.split(',') if r.strip()] if remarks 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)
# Display remarks as pills
if remarks_list:
st.markdown("### Additional Activities")
pills_html = "".join([f'{remark}' for remark in remarks_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 required fields!")
st.stop()
try:
genai.configure(api_key=api_key)
model = genai.GenerativeModel('gemini-1.5-flash')
# Build prompt with remarks
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. Include any additional learning activities if provided
6. Curiosity-sparking question for engagement
7. Relevant hashtags (5-7)
8. Format: Clear paragraphs, no markdown
Context:
- Career Goal: {goal}
- Learning Day: {day_number}
- Topics: {", ".join(topics_list)}
- Additional Activities: {", ".join(remarks_list) if remarks_list else "None"}
"""
with st.spinner("🚀 Crafting your viral post..."):
response = model.generate_content(prompt)
post = response.text
# Store post in session state for copying
st.session_state.post_content = post
# 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 with working functionality
if st.button("📋 Copy to Clipboard", key="copy_button", use_container_width=True,
type="primary", help="Click to copy post to clipboard"):
st.session_state.post_content = st.session_state.post_content.replace("◉", "•") # Revert bullets for plain text
st.write(f'',
unsafe_allow_html=True)
st.success("Copied to clipboard! Ready to paste on LinkedIn 🚀")
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