Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -14,6 +14,12 @@ load_dotenv()
|
|
| 14 |
genai.configure(api_key=os.getenv('GOOGLE_API_KEY'))
|
| 15 |
model = genai.GenerativeModel('gemini-2.0-flash')
|
| 16 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 17 |
# Hide Streamlit menu and footer
|
| 18 |
st.markdown("""
|
| 19 |
<style>
|
|
@@ -47,34 +53,49 @@ with col1:
|
|
| 47 |
temperature = st.slider('🌡️ Creativity Level', min_value=0.0, max_value=2.0, value=0.7,
|
| 48 |
help='Higher values make the output more creative but less focused')
|
| 49 |
|
| 50 |
-
# Generate button
|
| 51 |
-
|
| 52 |
if not skills or not product_service:
|
| 53 |
st.error('Please fill in both Skills and Product/Service fields')
|
| 54 |
else:
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 60 |
|
| 61 |
-
|
| 62 |
-
|
|
|
|
|
|
|
| 63 |
|
| 64 |
-
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
st.success('✨ Your offer is ready!')
|
| 71 |
-
|
| 72 |
-
# Display result in the right column
|
| 73 |
-
with col2:
|
| 74 |
-
st.markdown('### 📝 Generated Offer')
|
| 75 |
-
st.markdown(response.text)
|
| 76 |
-
except Exception as e:
|
| 77 |
-
st.error(f'An error occurred: {str(e)}')
|
| 78 |
|
| 79 |
# Footer
|
| 80 |
st.markdown('---')
|
|
|
|
| 14 |
genai.configure(api_key=os.getenv('GOOGLE_API_KEY'))
|
| 15 |
model = genai.GenerativeModel('gemini-2.0-flash')
|
| 16 |
|
| 17 |
+
# Initialize session state variables if they don't exist
|
| 18 |
+
if 'submitted' not in st.session_state:
|
| 19 |
+
st.session_state.submitted = False
|
| 20 |
+
if 'offer_result' not in st.session_state:
|
| 21 |
+
st.session_state.offer_result = ""
|
| 22 |
+
|
| 23 |
# Hide Streamlit menu and footer
|
| 24 |
st.markdown("""
|
| 25 |
<style>
|
|
|
|
| 53 |
temperature = st.slider('🌡️ Creativity Level', min_value=0.0, max_value=2.0, value=0.7,
|
| 54 |
help='Higher values make the output more creative but less focused')
|
| 55 |
|
| 56 |
+
# Generate button with callback
|
| 57 |
+
def generate_offer():
|
| 58 |
if not skills or not product_service:
|
| 59 |
st.error('Please fill in both Skills and Product/Service fields')
|
| 60 |
else:
|
| 61 |
+
# Set submitted flag to True
|
| 62 |
+
st.session_state.submitted = True
|
| 63 |
+
# Store input values in session state
|
| 64 |
+
st.session_state.skills = skills
|
| 65 |
+
st.session_state.product_service = product_service
|
| 66 |
+
st.session_state.target_audience = target_audience
|
| 67 |
+
st.session_state.temperature = temperature
|
| 68 |
+
|
| 69 |
+
st.button('Generate Offer 🎉', on_click=generate_offer)
|
| 70 |
+
|
| 71 |
+
# Results column
|
| 72 |
+
with col2:
|
| 73 |
+
# Check if form has been submitted
|
| 74 |
+
if st.session_state.submitted:
|
| 75 |
+
with st.spinner('Creating your perfect offer...'):
|
| 76 |
+
prompt = f"""Based on the following information, create a compelling offer:
|
| 77 |
+
Skills: {st.session_state.skills}
|
| 78 |
+
Product/Service: {st.session_state.product_service}
|
| 79 |
+
Target Audience: {st.session_state.target_audience if st.session_state.target_audience else 'General audience'}
|
| 80 |
+
|
| 81 |
+
Please create a professional and engaging offer that highlights the value proposition
|
| 82 |
+
and appeals to the target audience. Include a clear call to action."""
|
| 83 |
+
|
| 84 |
+
try:
|
| 85 |
+
# Create generation config with temperature
|
| 86 |
+
generation_config = genai.GenerationConfig(temperature=st.session_state.temperature)
|
| 87 |
|
| 88 |
+
# Pass the generation config to generate_content
|
| 89 |
+
response = model.generate_content(prompt, generation_config=generation_config)
|
| 90 |
+
st.session_state.offer_result = response.text
|
| 91 |
+
st.success('✨ Your offer is ready!')
|
| 92 |
|
| 93 |
+
# Display result
|
| 94 |
+
st.markdown('### 📝 Generated Offer')
|
| 95 |
+
st.markdown(st.session_state.offer_result)
|
| 96 |
+
except Exception as e:
|
| 97 |
+
st.error(f'An error occurred: {str(e)}')
|
| 98 |
+
st.session_state.submitted = False
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 99 |
|
| 100 |
# Footer
|
| 101 |
st.markdown('---')
|