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)}")