manuelcozar55 commited on
Commit
fdfd7ca
·
verified ·
1 Parent(s): 42d7a05

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -22
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 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:
@@ -125,15 +125,6 @@ def process_file(file, action, target_language=None, summary_length=None):
125
  else:
126
  return "Acción no válida"
127
 
128
- def answer_question(text, question):
129
- messages = [
130
- {"role": "system", "content": "Eres un asistente útil."},
131
- {"role": "user", "content": f"El documento es el siguiente:\n{text}"},
132
- {"role": "user", "content": question}
133
- ]
134
- response = llm_engine_hf.invoke(messages)
135
- return response.content
136
-
137
  def download_text(output_text, filename='output.txt'):
138
  if output_text:
139
  file_path = Path(filename)
@@ -160,27 +151,22 @@ with gr.Blocks() as demo:
160
 
161
  with gr.Column():
162
  output_text = gr.Textbox(label="Resultado", lines=20)
163
- question = gr.Textbox(label="Hacer una pregunta al documento", lines=2, visible=False)
164
- answer = gr.Textbox(label="Respuesta", lines=2, interactive=False, visible=False)
165
 
166
  def update_visible_elements(action):
167
  if action == "Traducir":
168
- return gr.update(visible=True), gr.update(visible=False), gr.update(visible=False), gr.update(visible=False), gr.update(visible=False)
169
  elif action == "Resumen":
170
- return gr.update(visible=False), gr.update(visible=True), gr.update(visible=False), gr.update(visible=False), gr.update(visible=False)
171
  elif action == "Clasificar":
172
- return gr.update(visible=False), gr.update(visible=False), gr.update(visible=True), gr.update(visible=True), gr.update(visible=False)
173
  else:
174
- return gr.update(visible=False), gr.update(visible=False), gr.update(visible=False), gr.update(visible(False)), gr.update(visible=False)
175
 
176
- action.change(update_visible_elements, inputs=action, outputs=[target_language, summary_length, question, output_text, answer])
177
 
178
  submit_button = gr.Button("Procesar")
179
  submit_button.click(process_file, inputs=[file, action, target_language, summary_length], outputs=output_text)
180
 
181
- question_button = gr.Button("Hacer Pregunta")
182
- question_button.click(answer_question, inputs=[output_text, question], outputs=answer)
183
-
184
  def generate_file():
185
  summary_text = output_text.value
186
  filename = 'translation.txt' if action.value == 'Traducir' else 'summary.txt'
 
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:
 
125
  else:
126
  return "Acción no válida"
127
 
 
 
 
 
 
 
 
 
 
128
  def download_text(output_text, filename='output.txt'):
129
  if output_text:
130
  file_path = Path(filename)
 
151
 
152
  with gr.Column():
153
  output_text = gr.Textbox(label="Resultado", lines=20)
 
 
154
 
155
  def update_visible_elements(action):
156
  if action == "Traducir":
157
+ return gr.update(visible=True), gr.update(visible=False), gr.update(visible(False))
158
  elif action == "Resumen":
159
+ return gr.update(visible=False), gr.update(visible=True), gr.update(visible(False))
160
  elif action == "Clasificar":
161
+ return gr.update(visible(False)), gr.update(visible(False)), gr.update(visible(True))
162
  else:
163
+ return gr.update(visible(False)), gr.update(visible(False)), gr.update(visible(False))
164
 
165
+ action.change(update_visible_elements, inputs=action, outputs=[target_language, summary_length, output_text])
166
 
167
  submit_button = gr.Button("Procesar")
168
  submit_button.click(process_file, inputs=[file, action, target_language, summary_length], outputs=output_text)
169
 
 
 
 
170
  def generate_file():
171
  summary_text = output_text.value
172
  filename = 'translation.txt' if action.value == 'Traducir' else 'summary.txt'