Update app.py
Browse files
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
|
| 51 |
elif summary_length == 'Medio':
|
| 52 |
-
length_instruction = "El resumen debe tener un m谩ximo de
|
| 53 |
else:
|
| 54 |
-
length_instruction = "El resumen debe tener un m谩ximo de
|
| 55 |
|
| 56 |
template = f'''
|
| 57 |
Por favor, lea detenidamente el siguiente documento:
|
|
@@ -80,7 +80,7 @@ def classify_text(text):
|
|
| 80 |
logits = outputs.logits
|
| 81 |
predicted_class_id = logits.argmax(dim=-1).item()
|
| 82 |
predicted_label = id2label[predicted_class_id]
|
| 83 |
-
return predicted_label
|
| 84 |
|
| 85 |
def translate(file, target_language):
|
| 86 |
# Leer el contenido del archivo subido
|
|
@@ -119,7 +119,8 @@ def process_file(file, action, target_language=None, summary_length=None):
|
|
| 119 |
else:
|
| 120 |
with open(file_path, 'r', encoding='utf-8') as f:
|
| 121 |
text = f.read()
|
| 122 |
-
|
|
|
|
| 123 |
elif action == "Traducir":
|
| 124 |
return translate(file, target_language)
|
| 125 |
else:
|
|
@@ -149,7 +150,7 @@ def create_download_file(output_text, filename='output.txt'):
|
|
| 149 |
|
| 150 |
# Crear la interfaz de Gradio
|
| 151 |
with gr.Blocks() as demo:
|
| 152 |
-
gr.Markdown("##
|
| 153 |
|
| 154 |
with gr.Row():
|
| 155 |
with gr.Column():
|
|
@@ -165,13 +166,13 @@ with gr.Blocks() as demo:
|
|
| 165 |
|
| 166 |
def update_visible_elements(action):
|
| 167 |
if action == "Traducir":
|
| 168 |
-
return gr.update(visible=True), gr.update(visible=False), gr.update(visible
|
| 169 |
elif action == "Resumen":
|
| 170 |
-
return gr.update(visible
|
| 171 |
elif action == "Clasificar":
|
| 172 |
-
return gr.update(visible
|
| 173 |
else:
|
| 174 |
-
return gr.update(visible
|
| 175 |
|
| 176 |
action.change(update_visible_elements, inputs=action, outputs=[target_language, summary_length, question, output_text, answer])
|
| 177 |
|
|
@@ -187,12 +188,17 @@ with gr.Blocks() as demo:
|
|
| 187 |
download_button = gr.Button("Descargar Resultado")
|
| 188 |
download_button.click(
|
| 189 |
fn=generate_file,
|
| 190 |
-
inputs=[],
|
| 191 |
outputs=gr.File()
|
| 192 |
)
|
| 193 |
|
| 194 |
question_button = gr.Button("Hacer Pregunta")
|
| 195 |
question_button.click(answer_question, inputs=[output_text, question], outputs=answer)
|
| 196 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 197 |
# Ejecutar la aplicaci贸n Gradio
|
| 198 |
-
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 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:
|
|
|
|
| 80 |
logits = outputs.logits
|
| 81 |
predicted_class_id = logits.argmax(dim=-1).item()
|
| 82 |
predicted_label = id2label[predicted_class_id]
|
| 83 |
+
return predicted_label, text
|
| 84 |
|
| 85 |
def translate(file, target_language):
|
| 86 |
# Leer el contenido del archivo subido
|
|
|
|
| 119 |
else:
|
| 120 |
with open(file_path, 'r', encoding='utf-8') as f:
|
| 121 |
text = f.read()
|
| 122 |
+
label, document_text = classify_text(text)
|
| 123 |
+
return f"Clasificaci贸n: {label}\n\nDocumento:\n{document_text}"
|
| 124 |
elif action == "Traducir":
|
| 125 |
return translate(file, target_language)
|
| 126 |
else:
|
|
|
|
| 150 |
|
| 151 |
# Crear la interfaz de Gradio
|
| 152 |
with gr.Blocks() as demo:
|
| 153 |
+
gr.Markdown("## LexAIcon")
|
| 154 |
|
| 155 |
with gr.Row():
|
| 156 |
with gr.Column():
|
|
|
|
| 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 |
|
|
|
|
| 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)
|