Update app.py
Browse files
app.py
CHANGED
|
@@ -470,39 +470,6 @@ Diferença Líquida: {total_adicionadas - total_removidas} linhas
|
|
| 470 |
"""
|
| 471 |
return peticao, peticao_corrigida, resumo_estatistico, criticas_texto, visualizacao_detalhada
|
| 472 |
|
| 473 |
-
def exportar_diferencas_html(caso, peticao_texto, correcao):
|
| 474 |
-
_, _, resumo_estatistico, criticas_texto, visualizacao_detalhada = comparar_peticao_melhorada(caso, peticao_texto, correcao)
|
| 475 |
-
|
| 476 |
-
html_content = f"""
|
| 477 |
-
<html>
|
| 478 |
-
<head>
|
| 479 |
-
<title>Diferenças na Petição</title>
|
| 480 |
-
<style>
|
| 481 |
-
body {{ font-family: Arial, sans-serif; margin: 20px; }}
|
| 482 |
-
.linha-igual {{ color: #000000; margin: 2px 0; }}
|
| 483 |
-
.linha-removida {{ color: #ffffff; background-color: #b30000; margin: 2px 0; padding: 2px; }}
|
| 484 |
-
.linha-adicionada {{ color: #ffffff; background-color: #006600; margin: 2px 0; padding: 2px; }}
|
| 485 |
-
h2 {{ color: #333; }}
|
| 486 |
-
pre {{ white-space: pre-wrap; }}
|
| 487 |
-
</style>
|
| 488 |
-
</head>
|
| 489 |
-
<body>
|
| 490 |
-
<h2>Estatísticas</h2>
|
| 491 |
-
<pre>{resumo_estatistico}</pre>
|
| 492 |
-
<h2>Mudanças Críticas</h2>
|
| 493 |
-
<pre>{criticas_texto}</pre>
|
| 494 |
-
<h2>Alterações Detalhadas</h2>
|
| 495 |
-
{visualizacao_detalhada}
|
| 496 |
-
</body>
|
| 497 |
-
</html>
|
| 498 |
-
"""
|
| 499 |
-
buffer = io.BytesIO()
|
| 500 |
-
buffer.write(html_content.encode('utf-8'))
|
| 501 |
-
buffer.seek(0)
|
| 502 |
-
|
| 503 |
-
nome_arquivo = f"diferencas_peticao_{datetime.now().strftime('%Y%m%d_%H%M%S')}.html"
|
| 504 |
-
return gr.File(value=buffer, label=nome_arquivo)
|
| 505 |
-
|
| 506 |
def interface_gradio():
|
| 507 |
with gr.Blocks(theme=gr.themes.Soft()) as demo:
|
| 508 |
gr.Markdown("# 📝 Corretor Avançado de Petições Iniciais (Critérios OAB)")
|
|
@@ -560,6 +527,7 @@ def interface_gradio():
|
|
| 560 |
arquivo_preview = gr.Textbox(label="Prévia do Conteúdo do Arquivo", lines=5, interactive=False)
|
| 561 |
btn_arquivo = gr.Button("🔍 Corrigir Petição (Arquivo)", variant="primary")
|
| 562 |
peticao_arquivo.change(fn=process_file, inputs=[peticao_arquivo], outputs=[arquivo_preview])
|
|
|
|
| 563 |
|
| 564 |
with gr.Row():
|
| 565 |
clear_btn = gr.Button("🗑️ Limpar Todos os Campos")
|
|
@@ -579,8 +547,7 @@ def interface_gradio():
|
|
| 579 |
visualizacao_detalhada_output = gr.HTML(label="📝 Alterações Detalhadas")
|
| 580 |
|
| 581 |
with gr.Row():
|
| 582 |
-
|
| 583 |
-
download_file = gr.File(label="Download", visible=False)
|
| 584 |
|
| 585 |
with gr.Accordion("📜 Histórico de Correções", open=False):
|
| 586 |
historico_output = gr.Markdown()
|
|
@@ -590,23 +557,44 @@ def interface_gradio():
|
|
| 590 |
outputs=historico_output
|
| 591 |
)
|
| 592 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 593 |
caso_btn.click(fn=gerar_caso_ficticio, inputs=[], outputs=[caso_input])
|
| 594 |
btn_texto.click(
|
|
|
|
|
|
|
|
|
|
|
|
|
| 595 |
fn=lambda caso, texto, treinamento: corrigir_peticao(caso, texto, None, treinamento),
|
| 596 |
inputs=[caso_input, peticao_texto, modo_treinamento],
|
| 597 |
outputs=[resultado_output]
|
|
|
|
|
|
|
|
|
|
|
|
|
| 598 |
)
|
| 599 |
btn_arquivo.click(
|
|
|
|
|
|
|
|
|
|
|
|
|
| 600 |
fn=lambda caso, arquivo, treinamento: corrigir_peticao(caso, None, arquivo, treinamento),
|
| 601 |
inputs=[caso_input, peticao_arquivo, modo_treinamento],
|
| 602 |
outputs=[resultado_output]
|
|
|
|
|
|
|
|
|
|
|
|
|
| 603 |
)
|
| 604 |
clear_btn.click(
|
| 605 |
fn=lambda: [None, None, None, None, "", "", "", "", "", gr.update(visible=False), gr.update(visible=False)],
|
| 606 |
inputs=None,
|
| 607 |
outputs=[caso_input, peticao_texto, peticao_arquivo, arquivo_preview, resultado_output, dica_contextual,
|
| 608 |
peticao_aluno_output, peticao_corrigida_output, resumo_alteracoes_output, criticas_output,
|
| 609 |
-
visualizacao_detalhada_output,
|
| 610 |
)
|
| 611 |
comparar_btn.click(
|
| 612 |
fn=comparar_peticao_melhorada,
|
|
@@ -615,15 +603,13 @@ def interface_gradio():
|
|
| 615 |
visualizacao_detalhada_output]
|
| 616 |
).then(
|
| 617 |
fn=lambda: gr.update(visible=True),
|
| 618 |
-
outputs=[
|
| 619 |
)
|
| 620 |
-
|
| 621 |
-
fn=
|
| 622 |
-
inputs=[
|
| 623 |
-
outputs=[
|
| 624 |
-
|
| 625 |
-
fn=lambda x: gr.update(visible=True, value=x),
|
| 626 |
-
outputs=[download_file]
|
| 627 |
)
|
| 628 |
|
| 629 |
with gr.Accordion("📘 Critérios Detalhados", open=False):
|
|
|
|
| 470 |
"""
|
| 471 |
return peticao, peticao_corrigida, resumo_estatistico, criticas_texto, visualizacao_detalhada
|
| 472 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 473 |
def interface_gradio():
|
| 474 |
with gr.Blocks(theme=gr.themes.Soft()) as demo:
|
| 475 |
gr.Markdown("# 📝 Corretor Avançado de Petições Iniciais (Critérios OAB)")
|
|
|
|
| 527 |
arquivo_preview = gr.Textbox(label="Prévia do Conteúdo do Arquivo", lines=5, interactive=False)
|
| 528 |
btn_arquivo = gr.Button("🔍 Corrigir Petição (Arquivo)", variant="primary")
|
| 529 |
peticao_arquivo.change(fn=process_file, inputs=[peticao_arquivo], outputs=[arquivo_preview])
|
| 530 |
+
processing_message = gr.Markdown("", visible=False) # Aviso de processamento
|
| 531 |
|
| 532 |
with gr.Row():
|
| 533 |
clear_btn = gr.Button("🗑️ Limpar Todos os Campos")
|
|
|
|
| 547 |
visualizacao_detalhada_output = gr.HTML(label="📝 Alterações Detalhadas")
|
| 548 |
|
| 549 |
with gr.Row():
|
| 550 |
+
copy_btn = gr.Button("📋 Copiar Diferenças", visible=False)
|
|
|
|
| 551 |
|
| 552 |
with gr.Accordion("📜 Histórico de Correções", open=False):
|
| 553 |
historico_output = gr.Markdown()
|
|
|
|
| 557 |
outputs=historico_output
|
| 558 |
)
|
| 559 |
|
| 560 |
+
def copy_differences(visualizacao_detalhada):
|
| 561 |
+
texto = "\n".join([linha for linha in visualizacao_detalhada.split('\n') if not linha.strip().startswith(('<style>', '</style>'))])
|
| 562 |
+
texto = texto.replace('<div class="linha-igual">', '').replace('<div class="linha-removida"><del>', 'REMOVIDO: ').replace('<div class="linha-adicionada"><ins>', 'ADICIONADO: ').replace('</div>', '').replace('</del>', '').replace('</ins>', '')
|
| 563 |
+
return texto
|
| 564 |
+
|
| 565 |
caso_btn.click(fn=gerar_caso_ficticio, inputs=[], outputs=[caso_input])
|
| 566 |
btn_texto.click(
|
| 567 |
+
fn=lambda: gr.update(value="⏳ Aguarde enquanto a correção é gerada...", visible=True),
|
| 568 |
+
inputs=None,
|
| 569 |
+
outputs=[processing_message]
|
| 570 |
+
).then(
|
| 571 |
fn=lambda caso, texto, treinamento: corrigir_peticao(caso, texto, None, treinamento),
|
| 572 |
inputs=[caso_input, peticao_texto, modo_treinamento],
|
| 573 |
outputs=[resultado_output]
|
| 574 |
+
).then(
|
| 575 |
+
fn=lambda: gr.update(value="", visible=False),
|
| 576 |
+
inputs=None,
|
| 577 |
+
outputs=[processing_message]
|
| 578 |
)
|
| 579 |
btn_arquivo.click(
|
| 580 |
+
fn=lambda: gr.update(value="⏳ Aguarde enquanto a correção é gerada...", visible=True),
|
| 581 |
+
inputs=None,
|
| 582 |
+
outputs=[processing_message]
|
| 583 |
+
).then(
|
| 584 |
fn=lambda caso, arquivo, treinamento: corrigir_peticao(caso, None, arquivo, treinamento),
|
| 585 |
inputs=[caso_input, peticao_arquivo, modo_treinamento],
|
| 586 |
outputs=[resultado_output]
|
| 587 |
+
).then(
|
| 588 |
+
fn=lambda: gr.update(value="", visible=False),
|
| 589 |
+
inputs=None,
|
| 590 |
+
outputs=[processing_message]
|
| 591 |
)
|
| 592 |
clear_btn.click(
|
| 593 |
fn=lambda: [None, None, None, None, "", "", "", "", "", gr.update(visible=False), gr.update(visible=False)],
|
| 594 |
inputs=None,
|
| 595 |
outputs=[caso_input, peticao_texto, peticao_arquivo, arquivo_preview, resultado_output, dica_contextual,
|
| 596 |
peticao_aluno_output, peticao_corrigida_output, resumo_alteracoes_output, criticas_output,
|
| 597 |
+
visualizacao_detalhada_output, copy_btn, processing_message]
|
| 598 |
)
|
| 599 |
comparar_btn.click(
|
| 600 |
fn=comparar_peticao_melhorada,
|
|
|
|
| 603 |
visualizacao_detalhada_output]
|
| 604 |
).then(
|
| 605 |
fn=lambda: gr.update(visible=True),
|
| 606 |
+
outputs=[copy_btn]
|
| 607 |
)
|
| 608 |
+
copy_btn.click(
|
| 609 |
+
fn=copy_differences,
|
| 610 |
+
inputs=[visualizacao_detalhada_output],
|
| 611 |
+
outputs=[gr.Textbox(visible=False)],
|
| 612 |
+
_js="function(text) { navigator.clipboard.writeText(text); alert('Diferenças copiadas para a área de transferência!'); return text; }"
|
|
|
|
|
|
|
| 613 |
)
|
| 614 |
|
| 615 |
with gr.Accordion("📘 Critérios Detalhados", open=False):
|