Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -51,31 +51,131 @@ col1, col2 = st.columns([4, 6])
|
|
51 |
with col1:
|
52 |
# Keep only the manual input tab
|
53 |
with st.container():
|
54 |
-
|
55 |
-
|
56 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
57 |
|
58 |
-
#
|
59 |
-
st.
|
60 |
-
|
61 |
|
62 |
-
|
63 |
-
|
64 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
65 |
|
66 |
-
#
|
67 |
-
st.
|
68 |
-
|
|
|
|
|
|
|
69 |
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
74 |
|
75 |
-
#
|
76 |
-
|
77 |
-
|
78 |
-
|
|
|
|
|
79 |
|
80 |
# Results column
|
81 |
with col2:
|
|
|
51 |
with col1:
|
52 |
# Keep only the manual input tab
|
53 |
with st.container():
|
54 |
+
skills = st.text_area('💪 Tus Habilidades', height=70,
|
55 |
+
help='Lista tus habilidades y experiencia clave')
|
56 |
+
product_service = st.text_area('🎯 Producto/Servicio', height=70,
|
57 |
+
help='Describe tu producto o servicio')
|
58 |
+
|
59 |
+
# Accordion for additional settings
|
60 |
+
with st.expander('⚙️ Configuración Avanzada'):
|
61 |
+
target_audience = st.text_area('👥 Público Objetivo', height=70,
|
62 |
+
help='Describe tu cliente o público ideal')
|
63 |
|
64 |
+
# Add file/image uploader here
|
65 |
+
uploaded_file = st.file_uploader("📄 Sube un archivo o imagen",
|
66 |
+
type=['txt', 'pdf', 'docx', 'jpg', 'jpeg', 'png'])
|
67 |
|
68 |
+
if uploaded_file is not None:
|
69 |
+
file_type = uploaded_file.name.split('.')[-1].lower()
|
70 |
+
|
71 |
+
# Handle text files
|
72 |
+
if file_type in ['txt', 'pdf', 'docx']:
|
73 |
+
if file_type == 'txt':
|
74 |
+
try:
|
75 |
+
file_content = uploaded_file.read().decode('utf-8')
|
76 |
+
except Exception as e:
|
77 |
+
st.error(f"Error al leer el archivo TXT: {str(e)}")
|
78 |
+
file_content = ""
|
79 |
+
|
80 |
+
elif file_type == 'pdf':
|
81 |
+
try:
|
82 |
+
import PyPDF2
|
83 |
+
pdf_reader = PyPDF2.PdfReader(uploaded_file)
|
84 |
+
file_content = ""
|
85 |
+
for page in pdf_reader.pages:
|
86 |
+
file_content += page.extract_text() + "\n"
|
87 |
+
except Exception as e:
|
88 |
+
st.error(f"Error al leer el archivo PDF: {str(e)}")
|
89 |
+
file_content = ""
|
90 |
+
|
91 |
+
elif file_type == 'docx':
|
92 |
+
try:
|
93 |
+
import docx
|
94 |
+
doc = docx.Document(uploaded_file)
|
95 |
+
file_content = "\n".join([para.text for para in doc.paragraphs])
|
96 |
+
except Exception as e:
|
97 |
+
st.error(f"Error al leer el archivo DOCX: {str(e)}")
|
98 |
+
file_content = ""
|
99 |
+
|
100 |
+
# Remove success message - no notification shown
|
101 |
+
|
102 |
+
# Set file type flag
|
103 |
+
is_image = False
|
104 |
+
|
105 |
+
# Handle image files
|
106 |
+
elif file_type in ['jpg', 'jpeg', 'png']:
|
107 |
+
try:
|
108 |
+
image = Image.open(uploaded_file)
|
109 |
+
st.image(image, caption="Imagen cargada", use_container_width=True)
|
110 |
+
|
111 |
+
image_bytes = uploaded_file.getvalue()
|
112 |
+
image_parts = [
|
113 |
+
{
|
114 |
+
"mime_type": uploaded_file.type,
|
115 |
+
"data": image_bytes
|
116 |
+
}
|
117 |
+
]
|
118 |
+
|
119 |
+
# Set file type flag
|
120 |
+
is_image = True
|
121 |
+
except Exception as e:
|
122 |
+
st.error(f"Error al procesar la imagen: {str(e)}")
|
123 |
+
is_image = False
|
124 |
|
125 |
+
# Selector de fórmula
|
126 |
+
formula_type = st.selectbox(
|
127 |
+
'📋 Tipo de Fórmula',
|
128 |
+
options=list(offer_formulas.keys()),
|
129 |
+
help='Selecciona el tipo de fórmula para tu oferta'
|
130 |
+
)
|
131 |
|
132 |
+
temperature = st.slider('🌡️ Nivel de Creatividad', min_value=0.0, max_value=2.0, value=0.7,
|
133 |
+
help='Valores más altos hacen que el resultado sea más creativo pero menos enfocado')
|
134 |
+
|
135 |
+
def generate_offer():
|
136 |
+
has_manual_input = bool(skills or product_service)
|
137 |
+
has_file_input = bool(uploaded_file is not None and not is_image)
|
138 |
+
has_image_input = bool(uploaded_file is not None and is_image)
|
139 |
+
|
140 |
+
# Simple validation - check if we have at least one input type
|
141 |
+
if not (has_manual_input or has_file_input or has_image_input):
|
142 |
+
st.error('Por favor ingresa texto o sube un archivo/imagen')
|
143 |
+
return
|
144 |
+
|
145 |
+
st.session_state.submitted = True
|
146 |
+
st.session_state.generated = False # Reset generated flag
|
147 |
+
|
148 |
+
# Store inputs based on what's available
|
149 |
+
if has_manual_input:
|
150 |
+
st.session_state.skills = skills if skills else ""
|
151 |
+
st.session_state.product_service = product_service if product_service else ""
|
152 |
+
|
153 |
+
if has_file_input:
|
154 |
+
st.session_state.file_content = file_content
|
155 |
+
|
156 |
+
if has_image_input:
|
157 |
+
st.session_state.image_parts = image_parts
|
158 |
+
|
159 |
+
# Set input type based on what's available
|
160 |
+
if has_image_input:
|
161 |
+
if has_manual_input:
|
162 |
+
st.session_state.input_type = "manual_image"
|
163 |
+
else:
|
164 |
+
st.session_state.input_type = "image"
|
165 |
+
else:
|
166 |
+
if has_manual_input and has_file_input:
|
167 |
+
st.session_state.input_type = "both"
|
168 |
+
elif has_file_input:
|
169 |
+
st.session_state.input_type = "file"
|
170 |
+
elif has_manual_input:
|
171 |
+
st.session_state.input_type = "manual"
|
172 |
|
173 |
+
# Store common settings
|
174 |
+
st.session_state.target_audience = target_audience
|
175 |
+
st.session_state.temperature = temperature
|
176 |
+
st.session_state.formula_type = formula_type
|
177 |
+
|
178 |
+
st.button('Generar Oferta 🎉', on_click=generate_offer)
|
179 |
|
180 |
# Results column
|
181 |
with col2:
|