JeCabrera commited on
Commit
fe52220
verified
1 Parent(s): f9b9c56

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +70 -12
app.py CHANGED
@@ -42,10 +42,51 @@ col1, col2 = st.columns([4, 6])
42
 
43
  # Main input section in left column
44
  with col1:
45
- skills = st.text_area('馃挭 Tus Habilidades', height=70,
46
- help='Lista tus habilidades y experiencia clave')
47
- product_service = st.text_area('馃幆 Producto/Servicio', height=70,
48
- help='Describe tu producto o servicio')
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
49
 
50
  # Accordion for additional settings
51
  with st.expander('鈿欙笍 Configuraci贸n Avanzada'):
@@ -66,14 +107,23 @@ with col1:
66
 
67
  # Generate button with callback
68
  def generate_offer():
69
- if not skills or not product_service:
70
  st.error('Por favor completa los campos de Habilidades y Producto/Servicio')
 
 
71
  else:
72
  # Set submitted flag to True
73
  st.session_state.submitted = True
 
74
  # Store input values in session state
75
- st.session_state.skills = skills
76
- st.session_state.product_service = product_service
 
 
 
 
 
 
77
  st.session_state.target_audience = target_audience
78
  st.session_state.temperature = temperature
79
  st.session_state.formula_type = formula_type
@@ -85,11 +135,19 @@ with col2:
85
  # Check if form has been submitted
86
  if st.session_state.submitted:
87
  with st.spinner('Creando tu oferta perfecta...'):
88
- prompt = f"""Based on the following information, create a compelling offer using the {st.session_state.formula_type} formula:
89
- Skills: {st.session_state.skills}
90
- Product/Service: {st.session_state.product_service}
91
- Target Audience: {st.session_state.target_audience if st.session_state.target_audience else 'General audience'}
92
-
 
 
 
 
 
 
 
 
93
  Formula Description:
94
  {offer_formulas[st.session_state.formula_type]["description"]}
95
 
 
42
 
43
  # Main input section in left column
44
  with col1:
45
+ # Add tabs for different input methods
46
+ input_tab1, input_tab2 = st.tabs(["Entrada Manual", "Subir Archivo"])
47
+
48
+ with input_tab1:
49
+ skills = st.text_area('馃挭 Tus Habilidades', height=70,
50
+ help='Lista tus habilidades y experiencia clave')
51
+ product_service = st.text_area('馃幆 Producto/Servicio', height=70,
52
+ help='Describe tu producto o servicio')
53
+
54
+ with input_tab2:
55
+ uploaded_file = st.file_uploader("Sube un archivo con tu informaci贸n", type=['txt', 'pdf', 'docx'])
56
+ if uploaded_file is not None:
57
+ # Handle different file types
58
+ file_type = uploaded_file.name.split('.')[-1].lower()
59
+
60
+ if file_type == 'txt':
61
+ # Read text file
62
+ file_content = uploaded_file.read().decode('utf-8')
63
+ st.success(f"Archivo cargado correctamente: {uploaded_file.name}")
64
+
65
+ elif file_type == 'pdf':
66
+ try:
67
+ import PyPDF2
68
+ pdf_reader = PyPDF2.PdfReader(uploaded_file)
69
+ file_content = ""
70
+ for page in pdf_reader.pages:
71
+ file_content += page.extract_text() + "\n"
72
+ st.success(f"Archivo PDF cargado correctamente: {uploaded_file.name}")
73
+ except Exception as e:
74
+ st.error(f"Error al leer el archivo PDF: {str(e)}")
75
+ file_content = ""
76
+
77
+ elif file_type == 'docx':
78
+ try:
79
+ import docx
80
+ doc = docx.Document(uploaded_file)
81
+ file_content = "\n".join([para.text for para in doc.paragraphs])
82
+ st.success(f"Archivo DOCX cargado correctamente: {uploaded_file.name}")
83
+ except Exception as e:
84
+ st.error(f"Error al leer el archivo DOCX: {str(e)}")
85
+ file_content = ""
86
+
87
+ # Display preview of file content
88
+ with st.expander("Vista previa del contenido"):
89
+ st.write(file_content[:500] + "..." if len(file_content) > 500 else file_content)
90
 
91
  # Accordion for additional settings
92
  with st.expander('鈿欙笍 Configuraci贸n Avanzada'):
 
107
 
108
  # Generate button with callback
109
  def generate_offer():
110
+ if input_tab1._active and (not skills or not product_service):
111
  st.error('Por favor completa los campos de Habilidades y Producto/Servicio')
112
+ elif input_tab2._active and (uploaded_file is None):
113
+ st.error('Por favor sube un archivo para generar la oferta')
114
  else:
115
  # Set submitted flag to True
116
  st.session_state.submitted = True
117
+
118
  # Store input values in session state
119
+ if input_tab1._active:
120
+ st.session_state.skills = skills
121
+ st.session_state.product_service = product_service
122
+ st.session_state.input_type = "manual"
123
+ else:
124
+ st.session_state.file_content = file_content
125
+ st.session_state.input_type = "file"
126
+
127
  st.session_state.target_audience = target_audience
128
  st.session_state.temperature = temperature
129
  st.session_state.formula_type = formula_type
 
135
  # Check if form has been submitted
136
  if st.session_state.submitted:
137
  with st.spinner('Creando tu oferta perfecta...'):
138
+ if st.session_state.input_type == "manual":
139
+ prompt = f"""Based on the following information, create a compelling offer using the {st.session_state.formula_type} formula:
140
+ Skills: {st.session_state.skills}
141
+ Product/Service: {st.session_state.product_service}
142
+ Target Audience: {st.session_state.target_audience if st.session_state.target_audience else 'General audience'}
143
+ """
144
+ else:
145
+ prompt = f"""Based on the following information from the uploaded file, create a compelling offer using the {st.session_state.formula_type} formula:
146
+ File Content: {st.session_state.file_content}
147
+ Target Audience: {st.session_state.target_audience if st.session_state.target_audience else 'General audience'}
148
+ """
149
+
150
+ prompt += f"""
151
  Formula Description:
152
  {offer_formulas[st.session_state.formula_type]["description"]}
153