Spaces:
Running
Running
File size: 1,803 Bytes
092bf98 d17104a 6d8a29a 092bf98 d17104a 092bf98 6d8a29a 092bf98 | 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 | import streamlit as st
from groq import Groq
import os
# ---- PAGE CONFIG ----
st.set_page_config(page_title="AI LinkedIn Post Generator", page_icon="💼")
st.title("💼 AI LinkedIn Post Generator")
st.write("Generate high-quality LinkedIn posts using AI 🚀")
# ---- API KEY ----
api_key = os.getenv("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")
# ---- USER INPUTS ----
tone = st.radio(
"Select Post Tone:",
["Professional", "Casual", "Motivational", "Storytelling"]
)
topic = st.text_input("Enter your topic")
audience = st.text_input("Target audience (e.g. students, developers)")
# ---- GENERATE BUTTON ----
if st.button("Generate Post"):
if not api_key:
st.error("API key not found. Add it in Hugging Face Secrets.")
elif not topic or not audience:
st.error("Please fill all fields")
else:
try:
client = Groq(api_key=api_key)
prompt = f"""
Write a LinkedIn post.
Topic: {topic}
Audience: {audience}
Tone: {tone}
Make it:
- Engaging and scroll-stopping
- Include a strong hook
- Well-structured body
- End with a call-to-action (CTA)
- Use emojis and spacing
- Add relevant hashtags
"""
response = client.chat.completions.create(
model="openai/gpt-oss-120b",
messages=[{"role": "user", "content": prompt}],
temperature=0.7,
max_tokens=500
)
post = response.choices[0].message.content
st.subheader("📄 Generated Post")
st.write(post)
st.code(post)
except Exception as e:
st.error(f"Error: {str(e)}") |