0o7Hunk commited on
Commit
6fe4f88
·
verified ·
1 Parent(s): 70692d5

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +78 -35
app.py CHANGED
@@ -1,4 +1,3 @@
1
- # ------------------ GENERATE ------------------
2
  import streamlit as st
3
  from groq import Groq
4
  import os
@@ -47,43 +46,87 @@ st.markdown("""
47
 
48
  # ------------------ TITLE ------------------
49
  st.title("💼 AI LinkedIn Post Generator")
50
- st.write("Create high-quality LinkedIn posts step-by-step 🚀")
51
 
52
- api_key = os.getenv("GROQ_API_KEY")
 
 
 
 
 
 
 
 
 
 
 
 
53
 
54
- if not api_key:
55
- st.error("⚠️ API key not found! Add GROQ_API_KEY in Hugging Face Secrets.")
56
- else:
57
- client = Groq(api_key=api_key)
 
 
 
58
 
59
- prompt = f"""
60
- Write a LinkedIn post with:
61
- Topic: {st.session_state.topic}
62
- Tone: {st.session_state.tone}
63
- Audience: {st.session_state.audience}
64
- Length: {st.session_state.length}
 
 
 
65
 
66
- Make it engaging, clear, and professional. Add hook and call-to-action.
67
- """
 
 
 
 
 
 
 
68
 
69
- with st.spinner("Generating your post... ✨"):
70
- try:
71
- response = client.chat.completions.create(
72
- model="mixtral-8x7b-32768",
73
- messages=[
74
- {"role": "user", "content": prompt}
75
- ],
76
- max_tokens=500
77
- )
 
 
 
 
 
 
 
 
 
 
 
 
78
 
79
- post = response.choices[0].message.content
80
-
81
- st.success("✅ Your LinkedIn Post is Ready!")
82
- st.markdown("### 📢 Generated Post")
83
- st.write(post)
84
-
85
- if st.button("🔄 Create Another"):
86
- st.session_state.step = 1
87
-
88
- except Exception as e:
89
- st.error(f"Error: {str(e)}")
 
 
 
 
 
 
 
 
 
1
  import streamlit as st
2
  from groq import Groq
3
  import os
 
46
 
47
  # ------------------ TITLE ------------------
48
  st.title("💼 AI LinkedIn Post Generator")
49
+ st.write("Let's craft an engaging LinkedIn post step-by-step 🚀")
50
 
51
+ # Initialize session state variables
52
+ if 'step' not in st.session_state:
53
+ st.session_state['step'] = 1
54
+ if 'topic' not in st.session_state:
55
+ st.session_state['topic'] = ''
56
+ if 'tone' not in st.session_state:
57
+ st.session_state['tone'] = ''
58
+ if 'audience' not in st.session_state:
59
+ st.session_state['audience'] = ''
60
+ if 'length' not in st.session_state:
61
+ st.session_state['length'] = 150
62
+ if 'post' not in st.session_state:
63
+ st.session_state['post'] = ''
64
 
65
+ # Step 1: Input Topic
66
+ if st.session_state['step'] == 1:
67
+ st.subheader("Step 1: What's the topic?")
68
+ topic_input = st.text_input("Enter the topic for your LinkedIn post", value=st.session_state['topic'])
69
+ if st.button("Next"):
70
+ st.session_state['topic'] = topic_input
71
+ st.session_state['step'] = 2
72
 
73
+ # Step 2: Input Tone
74
+ elif st.session_state['step'] == 2:
75
+ st.subheader("Step 2: What's the tone?")
76
+ tone_input = st.text_input("E.g., professional, friendly, inspiring", value=st.session_state['tone'])
77
+ if st.button("Next"):
78
+ st.session_state['tone'] = tone_input
79
+ st.session_state['step'] = 3
80
+ if st.button("Back"):
81
+ st.session_state['step'] = 1
82
 
83
+ # Step 3: Input Audience
84
+ elif st.session_state['step'] == 3:
85
+ st.subheader("Step 3: Who's the audience?")
86
+ audience_input = st.text_input("E.g., marketers, developers", value=st.session_state['audience'])
87
+ if st.button("Next"):
88
+ st.session_state['audience'] = audience_input
89
+ st.session_state['step'] = 4
90
+ if st.button("Back"):
91
+ st.session_state['step'] = 2
92
 
93
+ # Step 4: Input Length
94
+ elif st.session_state['step'] == 4:
95
+ st.subheader("Step 4: How long should the post be?")
96
+ length_input = st.slider("Number of words", min_value=50, max_value=500, value=st.session_state['length'])
97
+ if st.button("Generate Post"):
98
+ st.session_state['length'] = length_input
99
+ # Proceed to generate the post
100
+ # Fetch API key
101
+ api_key = os.getenv("GROQ_API_KEY")
102
+ if not api_key:
103
+ st.error("⚠️ API key not found! Add GROQ_API_KEY in Hugging Face Secrets.")
104
+ else:
105
+ client = Groq(api_key=api_key)
106
+ prompt = f"""
107
+ Write a LinkedIn post with:
108
+ Topic: {st.session_state['topic']}
109
+ Tone: {st.session_state['tone']}
110
+ Audience: {st.session_state['audience']}
111
+ Length: {st.session_state['length']} words
112
+ Make it engaging, clear, and professional. Add hook and call-to-action.
113
+ """
114
 
115
+ with st.spinner("Generating your post... ✨"):
116
+ try:
117
+ response = client.chat.completions.create(
118
+ model="mixtral-8x7b-32768",
119
+ messages=[{"role": "user", "content": prompt}],
120
+ max_tokens=600
121
+ )
122
+ post = response.choices[0].message.content
123
+ st.session_state['post'] = post
124
+ st.success("✅ Your LinkedIn Post is Ready!")
125
+ st.markdown("### 📢 Generated Post")
126
+ st.write(post)
127
+ if st.button("Create Another Post"):
128
+ st.session_state['step'] = 1
129
+ except Exception as e:
130
+ st.error(f"Error: {str(e)}")
131
+ if st.button("Back"):
132
+ st.session_state['step'] = 3