Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -4,7 +4,7 @@ import os
|
|
| 4 |
|
| 5 |
# ------------------ PAGE CONFIG ------------------
|
| 6 |
st.set_page_config(
|
| 7 |
-
page_title="
|
| 8 |
page_icon="πΌ",
|
| 9 |
layout="centered"
|
| 10 |
)
|
|
@@ -13,38 +13,43 @@ st.set_page_config(
|
|
| 13 |
st.markdown("""
|
| 14 |
<style>
|
| 15 |
body {
|
| 16 |
-
background: linear-gradient(135deg, #
|
| 17 |
}
|
| 18 |
.main {
|
| 19 |
-
background-color:
|
| 20 |
-
padding:
|
| 21 |
border-radius: 15px;
|
| 22 |
}
|
| 23 |
-
h1, h2, h3
|
| 24 |
-
color:
|
| 25 |
-
font-weight:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 26 |
}
|
| 27 |
.stButton>button {
|
| 28 |
-
background-color: #
|
| 29 |
color: white;
|
| 30 |
font-weight: bold;
|
| 31 |
-
border-radius:
|
| 32 |
padding: 10px;
|
| 33 |
}
|
| 34 |
.stTextInput>div>div>input, .stTextArea textarea {
|
| 35 |
-
background-color: #
|
| 36 |
-
color:
|
| 37 |
-
font-weight:
|
| 38 |
}
|
| 39 |
</style>
|
| 40 |
""", unsafe_allow_html=True)
|
| 41 |
|
| 42 |
# ------------------ TITLE ------------------
|
| 43 |
st.title("πΌ AI LinkedIn Post Generator")
|
| 44 |
-
st.write("
|
| 45 |
|
| 46 |
-
# ------------------ API KEY ------------------
|
| 47 |
-
api_key =
|
| 48 |
|
| 49 |
# ------------------ SESSION STATE ------------------
|
| 50 |
if "step" not in st.session_state:
|
|
@@ -69,8 +74,9 @@ elif st.session_state.step == 2:
|
|
| 69 |
elif st.session_state.step == 3:
|
| 70 |
audience = st.text_input("π₯ Target audience")
|
| 71 |
if st.button("Next β‘οΈ"):
|
| 72 |
-
|
| 73 |
-
|
|
|
|
| 74 |
|
| 75 |
# ------------------ STEP 4 ------------------
|
| 76 |
elif st.session_state.step == 4:
|
|
@@ -81,34 +87,34 @@ elif st.session_state.step == 4:
|
|
| 81 |
|
| 82 |
# ------------------ GENERATE ------------------
|
| 83 |
elif st.session_state.step == 5:
|
|
|
|
| 84 |
if not api_key:
|
| 85 |
-
st.error("β οΈ
|
| 86 |
else:
|
| 87 |
client = Groq(api_key=api_key)
|
| 88 |
|
| 89 |
prompt = f"""
|
| 90 |
-
Write a LinkedIn post with
|
| 91 |
Topic: {st.session_state.topic}
|
| 92 |
Tone: {st.session_state.tone}
|
| 93 |
Audience: {st.session_state.audience}
|
| 94 |
Length: {st.session_state.length}
|
| 95 |
|
| 96 |
-
Make it engaging,
|
| 97 |
"""
|
| 98 |
|
| 99 |
-
with st.spinner("
|
| 100 |
-
|
| 101 |
response = client.chat.completions.create(
|
| 102 |
-
model="
|
| 103 |
-
messages=[{"role": "user", "content": prompt}]
|
| 104 |
-
temperature=0.7,
|
| 105 |
-
max_tokens=500
|
| 106 |
)
|
| 107 |
|
| 108 |
post = response.choices[0].message.content
|
| 109 |
|
| 110 |
st.success("β
Your LinkedIn Post is Ready!")
|
| 111 |
-
|
|
|
|
|
|
|
| 112 |
|
| 113 |
if st.button("π Create Another"):
|
| 114 |
st.session_state.step = 1
|
|
|
|
| 4 |
|
| 5 |
# ------------------ PAGE CONFIG ------------------
|
| 6 |
st.set_page_config(
|
| 7 |
+
page_title="AI LinkedIn Post Generator",
|
| 8 |
page_icon="πΌ",
|
| 9 |
layout="centered"
|
| 10 |
)
|
|
|
|
| 13 |
st.markdown("""
|
| 14 |
<style>
|
| 15 |
body {
|
| 16 |
+
background: linear-gradient(135deg, #4facfe, #00f2fe);
|
| 17 |
}
|
| 18 |
.main {
|
| 19 |
+
background-color: white;
|
| 20 |
+
padding: 25px;
|
| 21 |
border-radius: 15px;
|
| 22 |
}
|
| 23 |
+
h1, h2, h3 {
|
| 24 |
+
color: #1f2937;
|
| 25 |
+
font-weight: 800;
|
| 26 |
+
}
|
| 27 |
+
p, label {
|
| 28 |
+
color: #374151;
|
| 29 |
+
font-weight: 600;
|
| 30 |
+
font-size: 16px;
|
| 31 |
}
|
| 32 |
.stButton>button {
|
| 33 |
+
background-color: #2563eb;
|
| 34 |
color: white;
|
| 35 |
font-weight: bold;
|
| 36 |
+
border-radius: 8px;
|
| 37 |
padding: 10px;
|
| 38 |
}
|
| 39 |
.stTextInput>div>div>input, .stTextArea textarea {
|
| 40 |
+
background-color: #f9fafb;
|
| 41 |
+
color: black;
|
| 42 |
+
font-weight: 600;
|
| 43 |
}
|
| 44 |
</style>
|
| 45 |
""", unsafe_allow_html=True)
|
| 46 |
|
| 47 |
# ------------------ TITLE ------------------
|
| 48 |
st.title("πΌ AI LinkedIn Post Generator")
|
| 49 |
+
st.write("Create high-quality LinkedIn posts step-by-step π")
|
| 50 |
|
| 51 |
+
# ------------------ LOAD API KEY FROM ENV ------------------
|
| 52 |
+
api_key = os.getenv("GROQ_API_KEY")
|
| 53 |
|
| 54 |
# ------------------ SESSION STATE ------------------
|
| 55 |
if "step" not in st.session_state:
|
|
|
|
| 74 |
elif st.session_state.step == 3:
|
| 75 |
audience = st.text_input("π₯ Target audience")
|
| 76 |
if st.button("Next β‘οΈ"):
|
| 77 |
+
if audience:
|
| 78 |
+
st.session_state.audience = audience
|
| 79 |
+
st.session_state.step = 4
|
| 80 |
|
| 81 |
# ------------------ STEP 4 ------------------
|
| 82 |
elif st.session_state.step == 4:
|
|
|
|
| 87 |
|
| 88 |
# ------------------ GENERATE ------------------
|
| 89 |
elif st.session_state.step == 5:
|
| 90 |
+
|
| 91 |
if not api_key:
|
| 92 |
+
st.error("β οΈ API key not found! Add GROQ_API_KEY in Hugging Face Secrets.")
|
| 93 |
else:
|
| 94 |
client = Groq(api_key=api_key)
|
| 95 |
|
| 96 |
prompt = f"""
|
| 97 |
+
Write a LinkedIn post with:
|
| 98 |
Topic: {st.session_state.topic}
|
| 99 |
Tone: {st.session_state.tone}
|
| 100 |
Audience: {st.session_state.audience}
|
| 101 |
Length: {st.session_state.length}
|
| 102 |
|
| 103 |
+
Make it engaging, clear, and professional. Add hook and call-to-action.
|
| 104 |
"""
|
| 105 |
|
| 106 |
+
with st.spinner("Generating your post... β¨"):
|
|
|
|
| 107 |
response = client.chat.completions.create(
|
| 108 |
+
model="llama3-70b-8192",
|
| 109 |
+
messages=[{"role": "user", "content": prompt}]
|
|
|
|
|
|
|
| 110 |
)
|
| 111 |
|
| 112 |
post = response.choices[0].message.content
|
| 113 |
|
| 114 |
st.success("β
Your LinkedIn Post is Ready!")
|
| 115 |
+
|
| 116 |
+
st.markdown("### π’ Generated Post")
|
| 117 |
+
st.write(post)
|
| 118 |
|
| 119 |
if st.button("π Create Another"):
|
| 120 |
st.session_state.step = 1
|