File size: 4,545 Bytes
3fe53b9
 
 
 
 
 
b0abaa3
 
 
3fe53b9
 
 
 
 
b0abaa3
3fe53b9
f0d2397
 
 
 
 
 
2f69897
 
 
 
 
 
 
 
 
3fe53b9
 
 
 
 
 
 
5c05cb8
 
2f69897
 
 
1376a64
 
 
 
2f69897
 
1376a64
 
 
 
 
2f69897
f0d2397
 
2f69897
1376a64
2f69897
f0d2397
 
 
 
 
 
 
 
1376a64
f0d2397
 
 
 
 
1376a64
f0d2397
 
 
 
 
 
 
 
 
 
 
2f69897
f0d2397
 
 
2f69897
1376a64
 
f0d2397
1376a64
 
 
 
 
 
 
 
 
 
f0d2397
1376a64
f0d2397
3fe53b9
 
 
2f69897
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
import streamlit as st
import google.generativeai as genai
import os
from dotenv import load_dotenv
from styles import get_custom_css

# Set page to wide mode to use full width
st.set_page_config(layout="wide")

# Load environment variables
load_dotenv()

# Configure Google Gemini API
genai.configure(api_key=os.getenv('GOOGLE_API_KEY'))
model = genai.GenerativeModel('gemini-2.0-flash')

# Initialize session state variables if they don't exist
if 'submitted' not in st.session_state:
    st.session_state.submitted = False
if 'offer_result' not in st.session_state:
    st.session_state.offer_result = ""

# Hide Streamlit menu and footer
st.markdown("""
<style>
#MainMenu {visibility: hidden;}
footer {visibility: hidden;}
header {visibility: hidden;}
</style>
""", unsafe_allow_html=True)

# Custom CSS
st.markdown(get_custom_css(), unsafe_allow_html=True)

# App title and description
st.title('🚀 Great Offer Generator')
st.markdown('''### Transform your skills into compelling offers!''')

# Create two columns for layout - left column 40%, right column 60%
col1, col2 = st.columns([4, 6])

# Main input section in left column
with col1:
    skills = st.text_area('💪 Tus Habilidades', height=70, 
                        help='Lista tus habilidades y experiencia clave')
    product_service = st.text_area('🎯 Producto/Servicio', height=70,
                                help='Describe tu producto o servicio')

    # Accordion for additional settings
    with st.expander('⚙️ Configuración Avanzada'):
        target_audience = st.text_area('👥 Público Objetivo', height=70,
                                    help='Describe tu cliente o público ideal')
        temperature = st.slider('🌡️ Nivel de Creatividad', min_value=0.0, max_value=2.0, value=0.7,
                            help='Valores más altos hacen que el resultado sea más creativo pero menos enfocado')

    # Generate button with callback
    def generate_offer():
        if not skills or not product_service:
            st.error('Por favor completa los campos de Habilidades y Producto/Servicio')
        else:
            # Set submitted flag to True
            st.session_state.submitted = True
            # Store input values in session state
            st.session_state.skills = skills
            st.session_state.product_service = product_service
            st.session_state.target_audience = target_audience
            st.session_state.temperature = temperature
            
    st.button('Generar Oferta 🎉', on_click=generate_offer)

# Results column
with col2:
    # Check if form has been submitted
    if st.session_state.submitted:
        with st.spinner('Creando tu oferta perfecta...'):
            prompt = f"""Based on the following information, create a compelling offer:
            Skills: {st.session_state.skills}
            Product/Service: {st.session_state.product_service}
            Target Audience: {st.session_state.target_audience if st.session_state.target_audience else 'General audience'}
            
            Please create a professional and engaging offer that highlights the value proposition
            and appeals to the target audience. Include a clear call to action."""
            
            try:
                # Create generation config with temperature
                generation_config = genai.GenerationConfig(temperature=st.session_state.temperature)
                
                # Pass the generation config to generate_content
                response = model.generate_content(prompt, generation_config=generation_config)
                st.session_state.offer_result = response.text
                
                # Display result (removed the "Your offer is ready!" message)
                st.markdown('### 📝 Oferta Generada')
                st.markdown(st.session_state.offer_result)
                
                # Add download button below the result with 80% width
                col_download, col_empty = st.columns([8, 2])
                with col_download:
                    st.download_button(
                        label="Descargar Oferta",
                        data=st.session_state.offer_result,
                        file_name="oferta_generada.txt",
                        mime="text/plain"
                    )
            except Exception as e:
                st.error(f'Ocurrió un error: {str(e)}')
                st.session_state.submitted = False

# Footer
st.markdown('---')
st.markdown('Made with ❤️ by Jesús Cabrera')