import gradio as gr import requests import os API_KEY = os.getenv("groc_api_key") API_URL = "https://api.groq.com/openai/v1/chat/completions" def generate_post(topic, tone, audience, length): prompt = f""" Write a high-quality LinkedIn post. Topic: {topic} Tone: {tone} Audience: {audience} Length: {length} Make it: - Engaging with strong hook 🔥 - Human and storytelling style - Add emojis naturally 😄🚀💡 - End with hashtags (5-8) """ headers = { "Authorization": f"Bearer {API_KEY}", "Content-Type": "application/json" } payload = { "model": "llama-3.1-8b-instant", "messages": [{"role": "user", "content": prompt}], "temperature": 0.8 } res = requests.post(API_URL, headers=headers, json=payload) if res.status_code == 200: return res.json()["choices"][0]["message"]["content"] return res.text # 🎨 CLEAN MODERN UI (NO BROKEN CSS) with gr.Blocks(theme=gr.themes.Soft()) as demo: gr.Markdown("""

🚀 LinkedIn AI Post Generator

Create viral posts in seconds with AI

""") with gr.Column(scale=1): with gr.Row(): topic = gr.Textbox(label="💡 Topic", placeholder="e.g. AI, Freelancing, Tech trends") tone = gr.Dropdown( ["Professional", "Motivational", "Storytelling", "Casual"], label="🎯 Tone" ) with gr.Row(): audience = gr.Textbox(label="👥 Audience", placeholder="e.g. Developers, Recruiters") length = gr.Dropdown(["Short", "Medium", "Long"], label="📏 Length") btn = gr.Button("✨ Generate Post") output = gr.Textbox( label="📢 Generated LinkedIn Post", lines=20 ) btn.click( generate_post, inputs=[topic, tone, audience, length], outputs=output ) demo.launch()