Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -49,44 +49,7 @@ 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 |
-
|
| 53 |
-
|
| 54 |
-
# ------------------ SESSION STATE ------------------
|
| 55 |
-
if "step" not in st.session_state:
|
| 56 |
-
st.session_state.step = 1
|
| 57 |
-
|
| 58 |
-
# ------------------ STEP 1 ------------------
|
| 59 |
-
if st.session_state.step == 1:
|
| 60 |
-
topic = st.text_input("π Enter your post topic")
|
| 61 |
-
if st.button("Next β‘οΈ"):
|
| 62 |
-
if topic:
|
| 63 |
-
st.session_state.topic = topic
|
| 64 |
-
st.session_state.step = 2
|
| 65 |
-
|
| 66 |
-
# ------------------ STEP 2 ------------------
|
| 67 |
-
elif st.session_state.step == 2:
|
| 68 |
-
tone = st.selectbox("π― Select tone", ["Professional", "Casual", "Inspirational", "Storytelling"])
|
| 69 |
-
if st.button("Next β‘οΈ"):
|
| 70 |
-
st.session_state.tone = tone
|
| 71 |
-
st.session_state.step = 3
|
| 72 |
-
|
| 73 |
-
# ------------------ STEP 3 ------------------
|
| 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:
|
| 83 |
-
length = st.selectbox("π Post length", ["Short", "Medium", "Long"])
|
| 84 |
-
if st.button("Generate π"):
|
| 85 |
-
st.session_state.length = length
|
| 86 |
-
st.session_state.step = 5
|
| 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.")
|
|
@@ -104,24 +67,23 @@ elif st.session_state.step == 5:
|
|
| 104 |
"""
|
| 105 |
|
| 106 |
with st.spinner("Generating your post... β¨"):
|
| 107 |
-
|
| 108 |
-
|
| 109 |
-
|
| 110 |
-
|
| 111 |
-
|
| 112 |
-
|
| 113 |
-
|
| 114 |
-
|
| 115 |
-
|
| 116 |
-
|
| 117 |
-
|
| 118 |
-
|
| 119 |
-
|
| 120 |
-
|
| 121 |
-
|
| 122 |
-
|
| 123 |
-
|
| 124 |
-
|
| 125 |
-
|
| 126 |
-
|
| 127 |
-
st.error(f"Error: {str(e)}")
|
|
|
|
| 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 |
if not api_key:
|
| 55 |
st.error("β οΈ API key not found! Add GROQ_API_KEY in Hugging Face Secrets.")
|
|
|
|
| 67 |
"""
|
| 68 |
|
| 69 |
with st.spinner("Generating your post... β¨"):
|
| 70 |
+
try:
|
| 71 |
+
response = client.chat.completions.create(
|
| 72 |
+
model="mixtral-8x7b-32768",
|
| 73 |
+
messages=[
|
| 74 |
+
{"role": "user", "content": prompt}
|
| 75 |
+
],
|
| 76 |
+
max_tokens=500
|
| 77 |
+
)
|
| 78 |
+
|
| 79 |
+
post = response.choices[0].message.content
|
| 80 |
+
|
| 81 |
+
st.success("β
Your LinkedIn Post is Ready!")
|
| 82 |
+
st.markdown("### π’ Generated Post")
|
| 83 |
+
st.write(post)
|
| 84 |
+
|
| 85 |
+
if st.button("π Create Another"):
|
| 86 |
+
st.session_state.step = 1
|
| 87 |
+
|
| 88 |
+
except Exception as e:
|
| 89 |
+
st.error(f"Error: {str(e)}")
|
|
|