Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -2,28 +2,26 @@ import gradio as gr
|
|
| 2 |
import requests
|
| 3 |
import os
|
| 4 |
|
| 5 |
-
# π Get API key from Hugging Face Secrets
|
| 6 |
API_KEY = os.getenv("groc_api_key")
|
| 7 |
-
|
| 8 |
API_URL = "https://api.groq.com/openai/v1/chat/completions"
|
| 9 |
|
| 10 |
|
| 11 |
def generate_linkedin_post(topic, tone, audience, length):
|
| 12 |
|
| 13 |
prompt = f"""
|
| 14 |
-
Write a
|
| 15 |
|
| 16 |
Topic: {topic}
|
| 17 |
Tone: {tone}
|
| 18 |
-
|
| 19 |
Length: {length}
|
| 20 |
|
| 21 |
-
|
| 22 |
-
-
|
| 23 |
-
-
|
| 24 |
-
-
|
| 25 |
-
-
|
| 26 |
-
-
|
| 27 |
"""
|
| 28 |
|
| 29 |
headers = {
|
|
@@ -33,39 +31,67 @@ def generate_linkedin_post(topic, tone, audience, length):
|
|
| 33 |
|
| 34 |
payload = {
|
| 35 |
"model": "llama-3.1-8b-instant",
|
| 36 |
-
"messages": [
|
| 37 |
-
|
| 38 |
-
],
|
| 39 |
-
"temperature": 0.7
|
| 40 |
}
|
| 41 |
|
| 42 |
-
|
| 43 |
|
| 44 |
-
if
|
| 45 |
-
return
|
| 46 |
-
|
| 47 |
-
return response.text
|
| 48 |
|
| 49 |
|
| 50 |
-
# π¨ UI
|
| 51 |
css = """
|
| 52 |
-
body {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 53 |
"""
|
| 54 |
|
| 55 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 56 |
|
| 57 |
-
with
|
| 58 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 59 |
|
| 60 |
with gr.Row():
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
audience = gr.Textbox(label="Target Audience")
|
| 64 |
-
length = gr.Dropdown(["Short", "Medium", "Long"])
|
| 65 |
|
| 66 |
-
btn = gr.Button("Generate")
|
| 67 |
|
| 68 |
-
output = gr.Textbox(
|
|
|
|
|
|
|
|
|
|
| 69 |
|
| 70 |
btn.click(
|
| 71 |
generate_linkedin_post,
|
|
|
|
| 2 |
import requests
|
| 3 |
import os
|
| 4 |
|
|
|
|
| 5 |
API_KEY = os.getenv("groc_api_key")
|
|
|
|
| 6 |
API_URL = "https://api.groq.com/openai/v1/chat/completions"
|
| 7 |
|
| 8 |
|
| 9 |
def generate_linkedin_post(topic, tone, audience, length):
|
| 10 |
|
| 11 |
prompt = f"""
|
| 12 |
+
Write a HIGHLY engaging LinkedIn post.
|
| 13 |
|
| 14 |
Topic: {topic}
|
| 15 |
Tone: {tone}
|
| 16 |
+
Audience: {audience}
|
| 17 |
Length: {length}
|
| 18 |
|
| 19 |
+
REQUIREMENTS:
|
| 20 |
+
- Start with a strong hook π₯
|
| 21 |
+
- Add relevant emojis naturally πππ‘
|
| 22 |
+
- Make it human, storytelling style
|
| 23 |
+
- Keep it LinkedIn viral optimized
|
| 24 |
+
- End with 5-8 hashtags
|
| 25 |
"""
|
| 26 |
|
| 27 |
headers = {
|
|
|
|
| 31 |
|
| 32 |
payload = {
|
| 33 |
"model": "llama-3.1-8b-instant",
|
| 34 |
+
"messages": [{"role": "user", "content": prompt}],
|
| 35 |
+
"temperature": 0.8
|
|
|
|
|
|
|
| 36 |
}
|
| 37 |
|
| 38 |
+
res = requests.post(API_URL, headers=headers, json=payload)
|
| 39 |
|
| 40 |
+
if res.status_code == 200:
|
| 41 |
+
return res.json()["choices"][0]["message"]["content"]
|
| 42 |
+
return res.text
|
|
|
|
| 43 |
|
| 44 |
|
| 45 |
+
# π¨ MODERN UI DESIGN
|
| 46 |
css = """
|
| 47 |
+
body {
|
| 48 |
+
background: linear-gradient(135deg, #f5f7fb, #e8f0ff);
|
| 49 |
+
}
|
| 50 |
+
|
| 51 |
+
.gradio-container {
|
| 52 |
+
max-width: 900px !important;
|
| 53 |
+
margin: auto !important;
|
| 54 |
+
}
|
| 55 |
+
|
| 56 |
+
textarea {
|
| 57 |
+
font-size: 16px !important;
|
| 58 |
+
background: white !important;
|
| 59 |
+
border-radius: 12px !important;
|
| 60 |
+
border: 1px solid #dbeafe !important;
|
| 61 |
+
}
|
| 62 |
+
|
| 63 |
+
button {
|
| 64 |
+
background: #2563eb !important;
|
| 65 |
+
color: white !important;
|
| 66 |
+
border-radius: 10px !important;
|
| 67 |
+
font-weight: bold !important;
|
| 68 |
+
}
|
| 69 |
"""
|
| 70 |
|
| 71 |
+
with gr.Blocks(css=css, theme=gr.themes.Soft()) as demo:
|
| 72 |
+
|
| 73 |
+
gr.Markdown("""
|
| 74 |
+
# π AI LinkedIn Post Generator
|
| 75 |
+
### Create viral LinkedIn posts with AI + emojis + storytelling β¨
|
| 76 |
+
""")
|
| 77 |
|
| 78 |
+
with gr.Row():
|
| 79 |
+
topic = gr.Textbox(label="π‘ Topic")
|
| 80 |
+
tone = gr.Dropdown(
|
| 81 |
+
["Professional", "Motivational", "Casual", "Storytelling"],
|
| 82 |
+
label="π― Tone"
|
| 83 |
+
)
|
| 84 |
|
| 85 |
with gr.Row():
|
| 86 |
+
audience = gr.Textbox(label="π₯ Target Audience")
|
| 87 |
+
length = gr.Dropdown(["Short", "Medium", "Long"], label="π Length")
|
|
|
|
|
|
|
| 88 |
|
| 89 |
+
btn = gr.Button("β¨ Generate Viral Post")
|
| 90 |
|
| 91 |
+
output = gr.Textbox(
|
| 92 |
+
label="π’ Generated LinkedIn Post",
|
| 93 |
+
lines=20
|
| 94 |
+
)
|
| 95 |
|
| 96 |
btn.click(
|
| 97 |
generate_linkedin_post,
|