SNA-AI commited on
Commit
3bb2daa
Β·
verified Β·
1 Parent(s): 46a167f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +56 -30
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 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 = {
@@ -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
- {"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,
 
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,