Spaces:
Running
Running
File size: 4,547 Bytes
70692d5 6fe4f88 092bf98 6fe4f88 c9eda21 6fe4f88 092bf98 6fe4f88 092bf98 6fe4f88 092bf98 6fe4f88 fc43288 6fe4f88 996a539 6fe4f88 12dfa0a 6fe4f88 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 | import streamlit as st
from groq import Groq
import os
# ------------------ PAGE CONFIG ------------------
st.set_page_config(
page_title="AI LinkedIn Post Generator",
page_icon="💼",
layout="centered"
)
# ------------------ CUSTOM CSS ------------------
st.markdown("""
<style>
body {
background: linear-gradient(135deg, #4facfe, #00f2fe);
}
.main {
background-color: white;
padding: 25px;
border-radius: 15px;
}
h1, h2, h3 {
color: #1f2937;
font-weight: 800;
}
p, label {
color: #374151;
font-weight: 600;
font-size: 16px;
}
.stButton>button {
background-color: #2563eb;
color: white;
font-weight: bold;
border-radius: 8px;
padding: 10px;
}
.stTextInput>div>div>input, .stTextArea textarea {
background-color: #f9fafb;
color: black;
font-weight: 600;
}
</style>
""", unsafe_allow_html=True)
# ------------------ TITLE ------------------
st.title("💼 AI LinkedIn Post Generator")
st.write("Let's craft an engaging LinkedIn post step-by-step 🚀")
# Initialize session state variables
if 'step' not in st.session_state:
st.session_state['step'] = 1
if 'topic' not in st.session_state:
st.session_state['topic'] = ''
if 'tone' not in st.session_state:
st.session_state['tone'] = ''
if 'audience' not in st.session_state:
st.session_state['audience'] = ''
if 'length' not in st.session_state:
st.session_state['length'] = 150
if 'post' not in st.session_state:
st.session_state['post'] = ''
# Step 1: Input Topic
if st.session_state['step'] == 1:
st.subheader("Step 1: What's the topic?")
topic_input = st.text_input("Enter the topic for your LinkedIn post", value=st.session_state['topic'])
if st.button("Next"):
st.session_state['topic'] = topic_input
st.session_state['step'] = 2
# Step 2: Input Tone
elif st.session_state['step'] == 2:
st.subheader("Step 2: What's the tone?")
tone_input = st.text_input("E.g., professional, friendly, inspiring", value=st.session_state['tone'])
if st.button("Next"):
st.session_state['tone'] = tone_input
st.session_state['step'] = 3
if st.button("Back"):
st.session_state['step'] = 1
# Step 3: Input Audience
elif st.session_state['step'] == 3:
st.subheader("Step 3: Who's the audience?")
audience_input = st.text_input("E.g., marketers, developers", value=st.session_state['audience'])
if st.button("Next"):
st.session_state['audience'] = audience_input
st.session_state['step'] = 4
if st.button("Back"):
st.session_state['step'] = 2
# Step 4: Input Length
elif st.session_state['step'] == 4:
st.subheader("Step 4: How long should the post be?")
length_input = st.slider("Number of words", min_value=50, max_value=500, value=st.session_state['length'])
if st.button("Generate Post"):
st.session_state['length'] = length_input
# Proceed to generate the post
# Fetch API key
api_key = os.getenv("GROQ_API_KEY")
if not api_key:
st.error("⚠️ API key not found! Add GROQ_API_KEY in Hugging Face Secrets.")
else:
client = Groq(api_key=api_key)
prompt = f"""
Write a LinkedIn post with:
Topic: {st.session_state['topic']}
Tone: {st.session_state['tone']}
Audience: {st.session_state['audience']}
Length: {st.session_state['length']} words
Make it engaging, clear, and professional. Add hook and call-to-action.
"""
with st.spinner("Generating your post... ✨"):
try:
response = client.chat.completions.create(
model="llama-3.1-8b-instant",
messages=[{"role": "user", "content": prompt}],
max_tokens=600
)
post = response.choices[0].message.content
st.session_state['post'] = post
st.success("✅ Your LinkedIn Post is Ready!")
st.markdown("### 📢 Generated Post")
st.write(post)
if st.button("Create Another Post"):
st.session_state['step'] = 1
except Exception as e:
st.error(f"Error: {str(e)}")
if st.button("Back"):
st.session_state['step'] = 3 |