Spaces:
Sleeping
Sleeping
Update app.py
Browse files41 unmodified lines4243444546474849505114 unmodified lines66676869707172737475767778795 unmodified lines858687888990919293949541 unmodified lines# Main input section in left columnwith 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 settingswith st.expander('鈿欙笍 Configuraci贸n Avanzada'):14 unmodified lines# Generate button with callbackdef 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 Truest.session_state.submitted = True# Store input values in session statest.session_state.skills = skillsst.session_state.product_service = product_servicest.session_state.target_audience = target_audiencest.session_state.temperature = temperaturest.session_state.formula_type = formula_type5 unmodified lines# Check if form has been submittedif st.session_state.submitted:with st.spinner('Creando tu oferta perfecta...'):prompt = f"""Based on the following information, create a compelling offer using the {st.session_state.formula_type} formula: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'}Formula Description:{offer_formulas[st.session_state.formula_type]["description"]}41 unmodified lines42434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919214 unmodified lines1071081091101111121131141151161171181191201211221231241251261271281295 unmodified lines13513613713813914014114214314414514614714814915015115215341 unmodified lines# Main input section in left columnwith col1:# Add tabs for different input methodsinput_tab1, input_tab2 = st.tabs(["Entrada Manual", "Subir Archivo"])with input_tab1: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')with input_tab2:uploaded_file = st.file_uploader("Sube un archivo con tu informaci贸n", type=['txt', 'pdf', 'docx'])if uploaded_file is not None:# Handle different file typesfile_type = uploaded_file.name.split('.')[-1].lower()if file_type == 'txt':# Read text filefile_content = uploaded_file.read().decode('utf-8')st.success(f"Archivo cargado correctamente: {uploaded_file.name}")elif file_type == 'pdf':try:import PyPDF2pdf_reader = PyPDF2.PdfReader(uploaded_file)file_content = ""for page in pdf_reader.pages:file_content += page.extract_text() + "\n"st.success(f"Archivo PDF cargado correctamente: {uploaded_file.name}")except Exception as e:st.error(f"Error al leer el archivo PDF: {str(e)}")file_content = ""elif file_type == 'docx':try:import docxdoc = docx.Document(uploaded_file)file_content = "\n".join([para.text for para in doc.paragraphs])st.success(f"Archivo DOCX cargado correctamente: {uploaded_file.name}")except Exception as e:st.error(f"Error al leer el archivo DOCX: {str(e)}")file_content = ""# Display preview of file contentwith st.expander("Vista previa del contenido"):st.write(file_content[:500] + "..." if len(file_content) > 500 else file_content)# Accordion for additional settingswith st.expander('鈿欙笍 Configuraci贸n Avanzada'):14 unmodified lines# Generate button with callbackdef generate_offer():if input_tab1._active and (not skills or not product_service):st.error('Por favor completa los campos de Habilidades y Producto/Servicio')elif input_tab2._active and (uploaded_file is None):st.error('Por favor sube un archivo para generar la oferta')else:# Set submitted flag to Truest.session_state.submitted = True# Store input values in session stateif input_tab1._active:st.session_state.skills = skillsst.session_state.product_service = product_servicest.session_state.input_type = "manual"else:st.session_state.file_content = file_contentst.session_state.input_type = "file"st.session_state.target_audience = target_audiencest.session_state.temperature = temperaturest.session_state.formula_type = formula_type5 unmodified lines# Check if form has been submittedif st.session_state.submitted:with st.spinner('Creando tu oferta perfecta...'):if st.session_state.input_type == "manual":prompt = f"""Based on the following information, create a compelling offer using the {st.session_state.formula_type} formula: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'}"""else:prompt = f"""Based on the following information from the uploaded file, create a compelling offer using the {st.session_state.formula_type} formula:File Content: {st.session_state.file_content}Target Audience: {st.session_state.target_audience if st.session_state.target_audience else 'General audience'}"""prompt += f"""Formula Description:{offer_formulas[st.session_state.formula_type]["description"]}
app.py+70-12