Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -3,7 +3,7 @@ import os
|
|
| 3 |
from utils import get_doc_content, call_openrouter
|
| 4 |
from config import DOCS
|
| 5 |
|
| 6 |
-
# 1. CSS para letras maiores
|
| 7 |
custom_css = """
|
| 8 |
label span { font-size: 22px !important; font-weight: bold !important; color: #2d2d2d !important; }
|
| 9 |
.gradio-container { font-family: 'Helvetica Neue', Arial, sans-serif; }
|
|
@@ -13,7 +13,6 @@ textarea { font-size: 18px !important; }
|
|
| 13 |
|
| 14 |
# 2. FUNÇÃO PARA SALVAR O TXT
|
| 15 |
def salvar_txt(conteudo):
|
| 16 |
-
"""Gera um arquivo temporário para download."""
|
| 17 |
if not conteudo:
|
| 18 |
return None
|
| 19 |
file_path = "analise_classica.txt"
|
|
@@ -21,7 +20,7 @@ def salvar_txt(conteudo):
|
|
| 21 |
f.write(conteudo)
|
| 22 |
return file_path
|
| 23 |
|
| 24 |
-
# 3. FUNÇÃO PRINCIPAL
|
| 25 |
def processar_analise(texto_usuario, modo, categoria_pergunta):
|
| 26 |
if not texto_usuario.strip():
|
| 27 |
return "Por favor, insira um texto.", "Aguardando...", None
|
|
@@ -29,75 +28,65 @@ def processar_analise(texto_usuario, modo, categoria_pergunta):
|
|
| 29 |
url = DOCS.get(categoria_pergunta)
|
| 30 |
perguntas_guia_ingles = get_doc_content(url)
|
| 31 |
|
| 32 |
-
# Prompt estruturado para TRADUÇÃO e ANÁLISE simultâneas
|
| 33 |
prompt_completo = f"""
|
| 34 |
VOCÊ É UM ESPECIALISTA EM FILOLOGIA CLÁSSICA E TRADUTOR TÉCNICO.
|
| 35 |
-
|
| 36 |
TAREFA:
|
| 37 |
-
1.
|
| 38 |
-
2.
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
- Mantenha o texto original (Grego/Latim) intacto.
|
| 43 |
-
- Formato da resposta:
|
| 44 |
-
Pergunta [Tradução para Português]:
|
| 45 |
-
Resposta: [Sua análise detalhada]
|
| 46 |
-
|
| 47 |
-
PROTOCOLO ORIGINAL (INGLÊS):
|
| 48 |
{perguntas_guia_ingles}
|
| 49 |
|
| 50 |
-
TEXTO
|
| 51 |
{texto_usuario}
|
| 52 |
"""
|
| 53 |
|
| 54 |
resposta_ia, modelo_vencedor = call_openrouter(prompt_completo, modo)
|
| 55 |
-
|
| 56 |
-
exibicao_final = f"--- RELATÓRIO DE ANÁLISE FILOLÓGICA ---\n\n{resposta_ia}"
|
| 57 |
caminho_arquivo = salvar_txt(exibicao_final)
|
| 58 |
|
| 59 |
-
return exibicao_final, f"Modelo
|
| 60 |
|
| 61 |
-
# 4. INTERFACE
|
| 62 |
with gr.Blocks(theme=gr.themes.Soft(), css=custom_css) as demo:
|
| 63 |
-
gr.Markdown("# 🏛️ AI for Classics
|
| 64 |
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
gr.Markdown("""
|
| 68 |
-
### Como funciona a seleção de modelos:
|
| 69 |
-
O sistema utiliza uma hierarquia. Se o primeiro modelo estiver fora do ar ou congestionado, o OpenRouter tentará automaticamente o próximo da lista.
|
| 70 |
-
|
| 71 |
-
| Estratégia | Hierarquia de Modelos (Ordem de tentativa) |
|
| 72 |
-
| :--- | :--- |
|
| 73 |
-
| **Alta Precisão** | 1. Claude 3.5 Sonnet | 2. GPT-4o | 3. Gemini 1.5 Pro |
|
| 74 |
-
| **Custo-Benefício** | 1. Gemini 1.5 Flash | 2. Command R | 3. Mistral Nemo |
|
| 75 |
-
""")
|
| 76 |
|
| 77 |
with gr.Row():
|
| 78 |
with gr.Column(scale=1):
|
| 79 |
-
input_text = gr.Textbox(
|
| 80 |
-
label="1. Texto Original (Grego/Latim)",
|
| 81 |
-
lines=10,
|
| 82 |
-
placeholder="Insira o trecho da obra clássica aqui..."
|
| 83 |
-
)
|
| 84 |
-
|
| 85 |
modo_radio = gr.Radio(
|
| 86 |
choices=["Alta Precisão (Filológico)", "Custo-Benefício (Triagem)"],
|
| 87 |
-
label="2. Estratégia
|
| 88 |
-
value="Alta Precisão (Filológico)"
|
| 89 |
-
info="Define a qualidade e o custo da análise (Consulte o painel informativo acima)."
|
| 90 |
)
|
| 91 |
-
|
| 92 |
cat_perguntas = gr.Dropdown(
|
| 93 |
choices=["SYNTAX", "MORPHOLOGY", "SEMANTICS"],
|
| 94 |
-
label="3. Protocolo
|
| 95 |
value="SYNTAX"
|
| 96 |
)
|
| 97 |
-
|
| 98 |
with gr.Row():
|
| 99 |
-
btn_limpar = gr.Button("Limpar
|
| 100 |
-
btn_rodar = gr.Button("🚀 EXECUTAR
|
| 101 |
|
| 102 |
with gr.Column(scale=1):
|
| 103 |
-
output_res = gr.Textbox(label="
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3 |
from utils import get_doc_content, call_openrouter
|
| 4 |
from config import DOCS
|
| 5 |
|
| 6 |
+
# 1. CSS para letras maiores
|
| 7 |
custom_css = """
|
| 8 |
label span { font-size: 22px !important; font-weight: bold !important; color: #2d2d2d !important; }
|
| 9 |
.gradio-container { font-family: 'Helvetica Neue', Arial, sans-serif; }
|
|
|
|
| 13 |
|
| 14 |
# 2. FUNÇÃO PARA SALVAR O TXT
|
| 15 |
def salvar_txt(conteudo):
|
|
|
|
| 16 |
if not conteudo:
|
| 17 |
return None
|
| 18 |
file_path = "analise_classica.txt"
|
|
|
|
| 20 |
f.write(conteudo)
|
| 21 |
return file_path
|
| 22 |
|
| 23 |
+
# 3. FUNÇÃO PRINCIPAL
|
| 24 |
def processar_analise(texto_usuario, modo, categoria_pergunta):
|
| 25 |
if not texto_usuario.strip():
|
| 26 |
return "Por favor, insira um texto.", "Aguardando...", None
|
|
|
|
| 28 |
url = DOCS.get(categoria_pergunta)
|
| 29 |
perguntas_guia_ingles = get_doc_content(url)
|
| 30 |
|
|
|
|
| 31 |
prompt_completo = f"""
|
| 32 |
VOCÊ É UM ESPECIALISTA EM FILOLOGIA CLÁSSICA E TRADUTOR TÉCNICO.
|
|
|
|
| 33 |
TAREFA:
|
| 34 |
+
1. Traduza o protocolo de perguntas abaixo para o PORTUGUÊS.
|
| 35 |
+
2. Responda cada pergunta em PORTUGUÊS analisando o texto original.
|
| 36 |
+
REGRAS: Mantenha o Grego/Latim intacto. Formato: Pergunta [Tradução] -> Resposta.
|
| 37 |
+
|
| 38 |
+
PROTOCOLO:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 39 |
{perguntas_guia_ingles}
|
| 40 |
|
| 41 |
+
TEXTO:
|
| 42 |
{texto_usuario}
|
| 43 |
"""
|
| 44 |
|
| 45 |
resposta_ia, modelo_vencedor = call_openrouter(prompt_completo, modo)
|
| 46 |
+
exibicao_final = f"--- RELATORIO DE ANALISE ---\n\n{resposta_ia}"
|
|
|
|
| 47 |
caminho_arquivo = salvar_txt(exibicao_final)
|
| 48 |
|
| 49 |
+
return exibicao_final, f"Modelo: {modelo_vencedor}", caminho_arquivo
|
| 50 |
|
| 51 |
+
# 4. INTERFACE
|
| 52 |
with gr.Blocks(theme=gr.themes.Soft(), css=custom_css) as demo:
|
| 53 |
+
gr.Markdown("# 🏛️ AI for Classics")
|
| 54 |
|
| 55 |
+
with gr.Accordion("ℹ️ Modelos e Estrategias", open=False):
|
| 56 |
+
gr.Markdown("- **Alta Precisão:** Claude 3.5, GPT-4o, Gemini Pro.\n- **Custo-Beneficio:** Gemini Flash, Command R, Mistral.")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 57 |
|
| 58 |
with gr.Row():
|
| 59 |
with gr.Column(scale=1):
|
| 60 |
+
input_text = gr.Textbox(label="1. Texto Original", lines=10)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 61 |
modo_radio = gr.Radio(
|
| 62 |
choices=["Alta Precisão (Filológico)", "Custo-Benefício (Triagem)"],
|
| 63 |
+
label="2. Estratégia",
|
| 64 |
+
value="Alta Precisão (Filológico)"
|
|
|
|
| 65 |
)
|
|
|
|
| 66 |
cat_perguntas = gr.Dropdown(
|
| 67 |
choices=["SYNTAX", "MORPHOLOGY", "SEMANTICS"],
|
| 68 |
+
label="3. Protocolo",
|
| 69 |
value="SYNTAX"
|
| 70 |
)
|
|
|
|
| 71 |
with gr.Row():
|
| 72 |
+
btn_limpar = gr.Button("Limpar")
|
| 73 |
+
btn_rodar = gr.Button("🚀 EXECUTAR", variant="primary")
|
| 74 |
|
| 75 |
with gr.Column(scale=1):
|
| 76 |
+
output_res = gr.Textbox(label="Analise Gerada", lines=18, interactive=False)
|
| 77 |
+
output_model = gr.Label(label="Status")
|
| 78 |
+
file_download = gr.File(label="Baixar TXT")
|
| 79 |
+
|
| 80 |
+
btn_rodar.click(
|
| 81 |
+
processar_analise,
|
| 82 |
+
inputs=[input_text, modo_radio, cat_perguntas],
|
| 83 |
+
outputs=[output_res, output_model, file_download]
|
| 84 |
+
)
|
| 85 |
+
|
| 86 |
+
btn_limpar.click(
|
| 87 |
+
lambda: ("", "Aguardando...", "", None),
|
| 88 |
+
outputs=[input_text, output_model, output_res, file_download]
|
| 89 |
+
)
|
| 90 |
+
|
| 91 |
+
if __name__ == "__main__":
|
| 92 |
+
demo.launch()
|