Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -378,52 +378,6 @@ def clean_vector(vec):
|
|
| 378 |
except:
|
| 379 |
return vec
|
| 380 |
|
| 381 |
-
def gerar_pdf_from_text(nome_arquivo: str, conteudo: str) -> str:
|
| 382 |
-
# garante que a pasta exista
|
| 383 |
-
import os
|
| 384 |
-
pasta = "/mnt/data"
|
| 385 |
-
os.makedirs(pasta, exist_ok=True)
|
| 386 |
-
caminho = f"{pasta}/{nome_arquivo}"
|
| 387 |
-
pdf = FPDF()
|
| 388 |
-
pdf.set_auto_page_break(auto=True, margin=12)
|
| 389 |
-
pdf.add_page()
|
| 390 |
-
pdf.set_font("Arial", size=10)
|
| 391 |
-
for line in conteudo.split("\n"):
|
| 392 |
-
pdf.multi_cell(0, 5, line)
|
| 393 |
-
|
| 394 |
-
pdf.output(caminho)
|
| 395 |
-
return caminho
|
| 396 |
-
|
| 397 |
-
|
| 398 |
-
|
| 399 |
-
def gerar_pdf_primal_dual_from_ui(model_txt, solution_html, steps_phase2_html, steps_phase1_html, summary_txt):
|
| 400 |
-
try:
|
| 401 |
-
clean = lambda s: re.sub(r"<[^>]*>", "", str(s or ""))
|
| 402 |
-
|
| 403 |
-
texto = "\n\n".join([
|
| 404 |
-
"MODELO:",
|
| 405 |
-
clean(model_txt),
|
| 406 |
-
"SOLUÇÃO:",
|
| 407 |
-
clean(solution_html),
|
| 408 |
-
"PHASE II – PASSOS (Primal):",
|
| 409 |
-
clean(steps_phase2_html),
|
| 410 |
-
"PHASE I – PASSOS (Dual):",
|
| 411 |
-
clean(steps_phase1_html),
|
| 412 |
-
"RESUMO:",
|
| 413 |
-
clean(summary_txt)
|
| 414 |
-
])
|
| 415 |
-
|
| 416 |
-
caminho = gerar_pdf_from_text("resultado_simplex.pdf", texto)
|
| 417 |
-
return caminho
|
| 418 |
-
|
| 419 |
-
except Exception as e:
|
| 420 |
-
erro_msg = f"Erro ao gerar PDF:\n\n{e}\n\n{traceback.format_exc()}"
|
| 421 |
-
print("### ERRO NA GERAÇÃO DO PDF ###")
|
| 422 |
-
print(erro_msg)
|
| 423 |
-
|
| 424 |
-
caminho = gerar_pdf_from_text("erro_gerar_pdf.pdf", erro_msg)
|
| 425 |
-
return caminho
|
| 426 |
-
|
| 427 |
|
| 428 |
# ---------------- Gradio handler ----------------
|
| 429 |
|
|
@@ -535,13 +489,7 @@ with gr.Blocks() as demo:
|
|
| 535 |
summary_out = gr.Textbox(label='Resumo', lines=8)
|
| 536 |
|
| 537 |
run.click(run_algorithms, inputs=[nvars, objective, cons, sense, gr.State(value='primal_and_dual')], outputs=[model_out, solution_out, steps_phase2_out, steps_phase1_out, summary_out])
|
| 538 |
-
|
| 539 |
-
gerar_pdf_primal_dual_from_ui,
|
| 540 |
-
inputs=[model_out, solution_out, steps_phase2_out, steps_phase1_out, summary_out],
|
| 541 |
-
outputs=pdf_out
|
| 542 |
-
)
|
| 543 |
-
btn_pdf = gr.Button("Gerar PDF")
|
| 544 |
-
pdf_out = gr.File(label="Baixar PDF")
|
| 545 |
|
| 546 |
|
| 547 |
gr.Examples(examples=[["2","60 30","2x1 + 4x2 >= 40\n3x1 + 2x2 >= 50","max"]], inputs=[nvars, objective, cons, sense])
|
|
|
|
| 378 |
except:
|
| 379 |
return vec
|
| 380 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 381 |
|
| 382 |
# ---------------- Gradio handler ----------------
|
| 383 |
|
|
|
|
| 489 |
summary_out = gr.Textbox(label='Resumo', lines=8)
|
| 490 |
|
| 491 |
run.click(run_algorithms, inputs=[nvars, objective, cons, sense, gr.State(value='primal_and_dual')], outputs=[model_out, solution_out, steps_phase2_out, steps_phase1_out, summary_out])
|
| 492 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 493 |
|
| 494 |
|
| 495 |
gr.Examples(examples=[["2","60 30","2x1 + 4x2 >= 40\n3x1 + 2x2 >= 50","max"]], inputs=[nvars, objective, cons, sense])
|