0o7Hunk commited on
Commit
c9eda21
Β·
verified Β·
1 Parent(s): 60d9c49

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +33 -27
app.py CHANGED
@@ -4,7 +4,7 @@ import os
4
 
5
  # ------------------ PAGE CONFIG ------------------
6
  st.set_page_config(
7
- page_title="πŸš€ AI LinkedIn Post Generator",
8
  page_icon="πŸ’Ό",
9
  layout="centered"
10
  )
@@ -13,38 +13,43 @@ st.set_page_config(
13
  st.markdown("""
14
  <style>
15
  body {
16
- background: linear-gradient(135deg, #1f4037, #99f2c8);
17
  }
18
  .main {
19
- background-color: rgba(0,0,0,0.6);
20
- padding: 20px;
21
  border-radius: 15px;
22
  }
23
- h1, h2, h3, h4, h5, h6, p, label {
24
- color: white !important;
25
- font-weight: bold !important;
 
 
 
 
 
26
  }
27
  .stButton>button {
28
- background-color: #ff4b2b;
29
  color: white;
30
  font-weight: bold;
31
- border-radius: 10px;
32
  padding: 10px;
33
  }
34
  .stTextInput>div>div>input, .stTextArea textarea {
35
- background-color: #222;
36
- color: white;
37
- font-weight: bold;
38
  }
39
  </style>
40
  """, unsafe_allow_html=True)
41
 
42
  # ------------------ TITLE ------------------
43
  st.title("πŸ’Ό AI LinkedIn Post Generator")
44
- st.write("✨ Create powerful, engaging LinkedIn posts step by step!")
45
 
46
- # ------------------ API KEY ------------------
47
- api_key = st.text_input("GROQ_API_KEY")
48
 
49
  # ------------------ SESSION STATE ------------------
50
  if "step" not in st.session_state:
@@ -69,8 +74,9 @@ elif st.session_state.step == 2:
69
  elif st.session_state.step == 3:
70
  audience = st.text_input("πŸ‘₯ Target audience")
71
  if st.button("Next ➑️"):
72
- st.session_state.audience = audience
73
- st.session_state.step = 4
 
74
 
75
  # ------------------ STEP 4 ------------------
76
  elif st.session_state.step == 4:
@@ -81,34 +87,34 @@ elif st.session_state.step == 4:
81
 
82
  # ------------------ GENERATE ------------------
83
  elif st.session_state.step == 5:
 
84
  if not api_key:
85
- st.error("⚠️ Please enter your GROQ API key!")
86
  else:
87
  client = Groq(api_key=api_key)
88
 
89
  prompt = f"""
90
- Write a LinkedIn post with the following details:
91
  Topic: {st.session_state.topic}
92
  Tone: {st.session_state.tone}
93
  Audience: {st.session_state.audience}
94
  Length: {st.session_state.length}
95
 
96
- Make it engaging, include hooks, emojis, and call-to-action.
97
  """
98
 
99
- with st.spinner("✨ Generating your post..."):
100
-
101
  response = client.chat.completions.create(
102
- model="openai/gpt-oss-120b",
103
- messages=[{"role": "user", "content": prompt}],
104
- temperature=0.7,
105
- max_tokens=500
106
  )
107
 
108
  post = response.choices[0].message.content
109
 
110
  st.success("βœ… Your LinkedIn Post is Ready!")
111
- st.markdown(f"### πŸ“’ Generated Post:\n\n*{post}*")
 
 
112
 
113
  if st.button("πŸ”„ Create Another"):
114
  st.session_state.step = 1
 
4
 
5
  # ------------------ PAGE CONFIG ------------------
6
  st.set_page_config(
7
+ page_title="AI LinkedIn Post Generator",
8
  page_icon="πŸ’Ό",
9
  layout="centered"
10
  )
 
13
  st.markdown("""
14
  <style>
15
  body {
16
+ background: linear-gradient(135deg, #4facfe, #00f2fe);
17
  }
18
  .main {
19
+ background-color: white;
20
+ padding: 25px;
21
  border-radius: 15px;
22
  }
23
+ h1, h2, h3 {
24
+ color: #1f2937;
25
+ font-weight: 800;
26
+ }
27
+ p, label {
28
+ color: #374151;
29
+ font-weight: 600;
30
+ font-size: 16px;
31
  }
32
  .stButton>button {
33
+ background-color: #2563eb;
34
  color: white;
35
  font-weight: bold;
36
+ border-radius: 8px;
37
  padding: 10px;
38
  }
39
  .stTextInput>div>div>input, .stTextArea textarea {
40
+ background-color: #f9fafb;
41
+ color: black;
42
+ font-weight: 600;
43
  }
44
  </style>
45
  """, unsafe_allow_html=True)
46
 
47
  # ------------------ TITLE ------------------
48
  st.title("πŸ’Ό AI LinkedIn Post Generator")
49
+ st.write("Create high-quality LinkedIn posts step-by-step πŸš€")
50
 
51
+ # ------------------ LOAD API KEY FROM ENV ------------------
52
+ api_key = os.getenv("GROQ_API_KEY")
53
 
54
  # ------------------ SESSION STATE ------------------
55
  if "step" not in st.session_state:
 
74
  elif st.session_state.step == 3:
75
  audience = st.text_input("πŸ‘₯ Target audience")
76
  if st.button("Next ➑️"):
77
+ if audience:
78
+ st.session_state.audience = audience
79
+ st.session_state.step = 4
80
 
81
  # ------------------ STEP 4 ------------------
82
  elif st.session_state.step == 4:
 
87
 
88
  # ------------------ GENERATE ------------------
89
  elif st.session_state.step == 5:
90
+
91
  if not api_key:
92
+ st.error("⚠️ API key not found! Add GROQ_API_KEY in Hugging Face Secrets.")
93
  else:
94
  client = Groq(api_key=api_key)
95
 
96
  prompt = f"""
97
+ Write a LinkedIn post with:
98
  Topic: {st.session_state.topic}
99
  Tone: {st.session_state.tone}
100
  Audience: {st.session_state.audience}
101
  Length: {st.session_state.length}
102
 
103
+ Make it engaging, clear, and professional. Add hook and call-to-action.
104
  """
105
 
106
+ with st.spinner("Generating your post... ✨"):
 
107
  response = client.chat.completions.create(
108
+ model="llama3-70b-8192",
109
+ messages=[{"role": "user", "content": prompt}]
 
 
110
  )
111
 
112
  post = response.choices[0].message.content
113
 
114
  st.success("βœ… Your LinkedIn Post is Ready!")
115
+
116
+ st.markdown("### πŸ“’ Generated Post")
117
+ st.write(post)
118
 
119
  if st.button("πŸ”„ Create Another"):
120
  st.session_state.step = 1