Spaces:
Sleeping
Sleeping
Update app.py
Browse files41 unmodified lines4243444546474845464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919214 unmodified lines1071081096911011111211311411511611711811975761201211221231241251261271281295 unmodified lines135136137138888990919213914014114214314414514614714814915015115215341 unmodified lines
# Main input section in left columnwith col1: # Add tabs for different input methods input_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') 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 types file_type = uploaded_file.name.split('.')[-1].lower() if file_type == 'txt': # Read text file file_content = uploaded_file.read().decode('utf-8') st.success(f"Archivo cargado correctamente: {uploaded_file.name}") elif file_type == 'pdf': try: import PyPDF2 pdf_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 docx doc = 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 content with st.expander("Vista previa del contenido"): st.write(file_content[:500] + "..." if len(file_content) > 500 else file_content)
# Accordion for additional settings with st.expander('⚙️ Configuración Avanzada'):14 unmodified lines
# Generate button with callback def generate_offer(): if not skills or not product_service: 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 True st.session_state.submitted = True # Store input values in session state if input_tab1._active: st.session_state.skills = skills st.session_state.product_service = product_service st.session_state.skills = skills st.session_state.product_service = product_service st.session_state.input_type = "manual" else: st.session_state.file_content = file_content st.session_state.input_type = "file" st.session_state.target_audience = target_audience st.session_state.temperature = temperature st.session_state.formula_type = formula_type5 unmodified lines # Check if form has been submitted if 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'} 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