SNA-AI commited on
Commit
159be23
·
verified ·
1 Parent(s): 3f06f5f

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +76 -0
app.py ADDED
@@ -0,0 +1,76 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ 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 professional LinkedIn post.
15
+
16
+ Topic: {topic}
17
+ Tone: {tone}
18
+ Target Audience: {audience}
19
+ Length: {length}
20
+
21
+ Requirements:
22
+ - Strong hook at start
23
+ - Human and engaging tone
24
+ - Add storytelling if possible
25
+ - Add hashtags at the end
26
+ - Make it viral-ready for LinkedIn
27
+ """
28
+
29
+ headers = {
30
+ "Authorization": f"Bearer {API_KEY}",
31
+ "Content-Type": "application/json"
32
+ }
33
+
34
+ payload = {
35
+ "model": "llama-3.1-8b-instant",
36
+ "messages": [
37
+ {"role": "user", "content": prompt}
38
+ ],
39
+ "temperature": 0.7
40
+ }
41
+
42
+ response = requests.post(API_URL, headers=headers, json=payload)
43
+
44
+ if response.status_code == 200:
45
+ return response.json()["choices"][0]["message"]["content"]
46
+ else:
47
+ return response.text
48
+
49
+
50
+ # 🎨 UI
51
+ css = """
52
+ body { background-color: #f5f7fb; }
53
+ """
54
+
55
+ demo = gr.Blocks(css=css, theme=gr.themes.Soft())
56
+
57
+ with demo:
58
+ gr.Markdown("# AI LinkedIn Post Generator 🚀")
59
+
60
+ with gr.Row():
61
+ topic = gr.Textbox(label="Topic")
62
+ tone = gr.Dropdown(["Professional", "Motivational", "Casual", "Storytelling"])
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(label="Generated Post", lines=20)
69
+
70
+ btn.click(
71
+ generate_linkedin_post,
72
+ inputs=[topic, tone, audience, length],
73
+ outputs=output
74
+ )
75
+
76
+ demo.launch()