Spaces:
Sleeping
Sleeping
File size: 2,054 Bytes
159be23 e208a21 159be23 5534c0f 159be23 e208a21 159be23 3bb2daa 159be23 e208a21 159be23 3bb2daa 159be23 3bb2daa 159be23 3bb2daa 159be23 e208a21 3bb2daa e208a21 3bb2daa 159be23 e208a21 159be23 e208a21 159be23 e208a21 159be23 e208a21 159be23 e208a21 159be23 | 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 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 | 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() |