Spaces:
Sleeping
Sleeping
| 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(""" | |
| <div style="text-align:center;"> | |
| <h1>π LinkedIn AI Post Generator</h1> | |
| <p style="color:gray;">Create viral posts in seconds with AI</p> | |
| </div> | |
| """) | |
| 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() |