SNA-AI's picture
Update app.py
e208a21 verified
Raw
History Blame Contribute Delete
2.05 kB
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()