manuelcozar55 commited on
Commit
d969e40
verified
1 Parent(s): 5cfd5eb

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +17 -32
app.py CHANGED
@@ -47,11 +47,11 @@ def summarize(file, summary_length):
47
  text = f.read()
48
 
49
  if summary_length == 'Corto':
50
- length_instruction = "El resumen debe tener un m谩ximo de 100 palabras."
51
  elif summary_length == 'Medio':
52
- length_instruction = "El resumen debe tener un m谩ximo de 500 palabras."
53
  else:
54
- length_instruction = "El resumen debe tener un m谩ximo de 1000 palabras."
55
 
56
  template = f'''
57
  Por favor, lea detenidamente el siguiente documento:
@@ -158,44 +158,23 @@ with gr.Blocks() as demo:
158
  action = gr.Radio(label="Seleccione una acci贸n", choices=["Resumen", "Clasificar", "Traducir"])
159
  target_language = gr.Dropdown(label="Seleccionar idioma de traducci贸n", choices=["en", "fr", "de"], visible=False)
160
  summary_length = gr.Radio(label="Seleccione la longitud del resumen", choices=["Corto", "Medio", "Largo"], visible=False)
161
- question = gr.Textbox(label="Hacer una pregunta al documento", lines=1, visible=False)
162
- question_button = gr.Button("Enviar Pregunta", visible=False)
163
 
164
  with gr.Column():
165
  output_text = gr.Textbox(label="Resultado", lines=20)
166
- answer = gr.Textbox(label="Respuesta", lines=1, interactive=False, visible=False)
 
167
 
168
  def update_visible_elements(action):
169
  if action == "Traducir":
170
- target_language.update(visible=True)
171
- summary_length.update(visible=False)
172
- question.update(visible=False)
173
- question_button.update(visible=False)
174
- output_text.update(visible=True)
175
- answer.update(visible=False)
176
  elif action == "Resumen":
177
- target_language.update(visible=False)
178
- summary_length.update(visible=True)
179
- question.update(visible(False))
180
- question_button.update(visible(False))
181
- output_text.update(visible=True)
182
- answer.update(visible(False))
183
  elif action == "Clasificar":
184
- target_language.update(visible(False))
185
- summary_length.update(visible(False))
186
- question.update(visible=True)
187
- question_button.update(visible=True)
188
- output_text.update(visible=True)
189
- answer.update(visible(True))
190
  else:
191
- target_language.update(visible(False))
192
- summary_length.update(visible(False))
193
- question.update(visible(False))
194
- question_button.update(visible(False))
195
- output_text.update(visible(False))
196
- answer.update(visible(False))
197
 
198
- action.change(update_visible_elements, inputs=action, outputs=[target_language, summary_length, question, question_button, output_text, answer])
199
 
200
  submit_button = gr.Button("Procesar")
201
  submit_button.click(process_file, inputs=[file, action, target_language, summary_length], outputs=output_text)
@@ -209,11 +188,17 @@ with gr.Blocks() as demo:
209
  download_button = gr.Button("Descargar Resultado")
210
  download_button.click(
211
  fn=generate_file,
212
- inputs=[],
213
  outputs=gr.File()
214
  )
215
 
 
216
  question_button.click(answer_question, inputs=[output_text, question], outputs=answer)
217
 
 
 
 
 
 
218
  # Ejecutar la aplicaci贸n Gradio
219
  demo.launch(share=True)
 
47
  text = f.read()
48
 
49
  if summary_length == 'Corto':
50
+ length_instruction = "El resumen debe tener un m谩ximo de 5 puntos."
51
  elif summary_length == 'Medio':
52
+ length_instruction = "El resumen debe tener un m谩ximo de 10 puntos."
53
  else:
54
+ length_instruction = "El resumen debe tener un m谩ximo de 15 puntos."
55
 
56
  template = f'''
57
  Por favor, lea detenidamente el siguiente documento:
 
158
  action = gr.Radio(label="Seleccione una acci贸n", choices=["Resumen", "Clasificar", "Traducir"])
159
  target_language = gr.Dropdown(label="Seleccionar idioma de traducci贸n", choices=["en", "fr", "de"], visible=False)
160
  summary_length = gr.Radio(label="Seleccione la longitud del resumen", choices=["Corto", "Medio", "Largo"], visible=False)
 
 
161
 
162
  with gr.Column():
163
  output_text = gr.Textbox(label="Resultado", lines=20)
164
+ question = gr.Textbox(label="Hacer una pregunta al documento", lines=2, visible=False)
165
+ answer = gr.Textbox(label="Respuesta", lines=2, interactive=False, visible=False)
166
 
167
  def update_visible_elements(action):
168
  if action == "Traducir":
169
+ return gr.update(visible=True), gr.update(visible=False), gr.update(visible(False)), gr.update(visible(False)), gr.update(visible(False))
 
 
 
 
 
170
  elif action == "Resumen":
171
+ return gr.update(visible(False)), gr.update(visible(True)), gr.update(visible(False)), gr.update(visible(False)), gr.update(visible(False))
 
 
 
 
 
172
  elif action == "Clasificar":
173
+ return gr.update(visible(False)), gr.update(visible(False)), gr.update(visible(True)), gr.update(visible(True)), gr.update(visible(True))
 
 
 
 
 
174
  else:
175
+ return gr.update(visible(False)), gr.update(visible(False)), gr.update(visible(False)), gr.update(visible(False)), gr.update(visible(False))
 
 
 
 
 
176
 
177
+ action.change(update_visible_elements, inputs=action, outputs=[target_language, summary_length, question, output_text, answer])
178
 
179
  submit_button = gr.Button("Procesar")
180
  submit_button.click(process_file, inputs=[file, action, target_language, summary_length], outputs=output_text)
 
188
  download_button = gr.Button("Descargar Resultado")
189
  download_button.click(
190
  fn=generate_file,
191
+ inputs=[output_text],
192
  outputs=gr.File()
193
  )
194
 
195
+ question_button = gr.Button("Hacer Pregunta")
196
  question_button.click(answer_question, inputs=[output_text, question], outputs=answer)
197
 
198
+ with gr.Row():
199
+ question.render()
200
+ question_button.render()
201
+ answer.render()
202
+
203
  # Ejecutar la aplicaci贸n Gradio
204
  demo.launch(share=True)