Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,33 +1,36 @@
|
|
| 1 |
import gradio as gr
|
|
|
|
| 2 |
from utils import get_doc_content, call_openrouter
|
| 3 |
from config import DOCS
|
| 4 |
|
| 5 |
-
# CSS
|
| 6 |
custom_css = """
|
| 7 |
-
label span {
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
}
|
| 12 |
-
.gradio-container {
|
| 13 |
-
font-family: 'Helvetica Neue', Arial, sans-serif;
|
| 14 |
-
}
|
| 15 |
-
button {
|
| 16 |
-
font-size: 20px !important;
|
| 17 |
-
}
|
| 18 |
-
textarea {
|
| 19 |
-
font-size: 18px !important;
|
| 20 |
-
}
|
| 21 |
"""
|
| 22 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 23 |
def processar_analise(texto_usuario, modo, categoria_pergunta):
|
| 24 |
if not texto_usuario.strip():
|
| 25 |
return "Por favor, insira um texto.", "Aguardando...", None
|
| 26 |
|
|
|
|
| 27 |
url = DOCS.get(categoria_pergunta)
|
| 28 |
perguntas_guia_ingles = get_doc_content(url)
|
| 29 |
|
| 30 |
-
# Prompt
|
| 31 |
prompt_completo = f"""
|
| 32 |
VOCÊ É UM ESPECIALISTA EM FILOLOGIA CLÁSSICA E TRADUTOR TÉCNICO.
|
| 33 |
|
|
@@ -49,6 +52,61 @@ def processar_analise(texto_usuario, modo, categoria_pergunta):
|
|
| 49 |
{texto_usuario}
|
| 50 |
"""
|
| 51 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 52 |
resposta_ia, modelo_vencedor = call_openrouter(prompt_completo, modo)
|
| 53 |
|
| 54 |
# Criamos a exibição final
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
+
import os
|
| 3 |
from utils import get_doc_content, call_openrouter
|
| 4 |
from config import DOCS
|
| 5 |
|
| 6 |
+
# 1. CSS para letras maiores e rótulos negritados
|
| 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; }
|
| 10 |
+
button { font-size: 18px !important; }
|
| 11 |
+
textarea { font-size: 18px !important; }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 12 |
"""
|
| 13 |
|
| 14 |
+
# 2. FUNÇÃO PARA SALVAR O TXT (Definida ANTES de ser usada)
|
| 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"
|
| 20 |
+
with open(file_path, "w", encoding="utf-8") as f:
|
| 21 |
+
f.write(conteudo)
|
| 22 |
+
return file_path
|
| 23 |
+
|
| 24 |
+
# 3. FUNÇÃO PRINCIPAL DE PROCESSAMENTO
|
| 25 |
def processar_analise(texto_usuario, modo, categoria_pergunta):
|
| 26 |
if not texto_usuario.strip():
|
| 27 |
return "Por favor, insira um texto.", "Aguardando...", None
|
| 28 |
|
| 29 |
+
# Busca as perguntas originais (em inglês) do Google Docs
|
| 30 |
url = DOCS.get(categoria_pergunta)
|
| 31 |
perguntas_guia_ingles = get_doc_content(url)
|
| 32 |
|
| 33 |
+
# Prompt estruturado para TRADUÇÃO e ANÁLISE simultâneas
|
| 34 |
prompt_completo = f"""
|
| 35 |
VOCÊ É UM ESPECIALISTA EM FILOLOGIA CLÁSSICA E TRADUTOR TÉCNICO.
|
| 36 |
|
|
|
|
| 52 |
{texto_usuario}
|
| 53 |
"""
|
| 54 |
|
| 55 |
+
# Chama a IA via OpenRouter (usando a lógica de fallback do utils.py)
|
| 56 |
+
resposta_ia, modelo_vencedor = call_openrouter(prompt_completo, modo)
|
| 57 |
+
|
| 58 |
+
# Formatação da exibição final
|
| 59 |
+
exibicao_final = f"--- RELATÓRIO DE ANÁLISE FILOLÓGICA ---\n\n{resposta_ia}"
|
| 60 |
+
|
| 61 |
+
# Gera o arquivo para o componente de download (CHAMANDO A FUNÇÃO DEFINIDA NO PASSO 2)
|
| 62 |
+
caminho_arquivo = salvar_txt(exibicao_final)
|
| 63 |
+
|
| 64 |
+
return exibicao_final, f"Modelo: {modelo_vencedor}", caminho_arquivo
|
| 65 |
+
|
| 66 |
+
# 4. INTERFACE GRADIO
|
| 67 |
+
with gr.Blocks(theme=gr.themes.Soft(), css=custom_css) as demo:
|
| 68 |
+
gr.Markdown("# 🏛️ AI for Classics: Ferramenta de Pesquisa")
|
| 69 |
+
|
| 70 |
+
with gr.Row():
|
| 71 |
+
with gr.Column(scale=1):
|
| 72 |
+
input_text = gr.Textbox(label="1. Texto Original (Grego/Latim)", lines=10, placeholder="Cole o texto aqui...")
|
| 73 |
+
modo_radio = gr.Radio(["Alta Precisão (Filológico)", "Custo-Benefício (Triagem)"], label="2. Estratégia", value="Alta Precisão (Filológico)")
|
| 74 |
+
cat_perguntas = gr.Dropdown(choices=["SYNTAX", "MORPHOLOGY", "SEMANTICS"], label="3. Protocolo", value="SYNTAX")
|
| 75 |
+
|
| 76 |
+
with gr.Row():
|
| 77 |
+
btn_limpar = gr.Button("Clear/Limpar")
|
| 78 |
+
btn_rodar = gr.Button("🚀 EXECUTAR ANÁLISE", variant="primary")
|
| 79 |
+
|
| 80 |
+
with gr.Column(scale=1):
|
| 81 |
+
output_res = gr.Textbox(label="Resultado e Análise", lines=15, interactive=False)
|
| 82 |
+
output_model = gr.Label(label="Status")
|
| 83 |
+
file_download = gr.File(label="Baixar resultado em .txt")
|
| 84 |
+
|
| 85 |
+
# Ações dos botões
|
| 86 |
+
btn_rodar.click(
|
| 87 |
+
processar_analise,
|
| 88 |
+
inputs=[input_text, modo_radio, cat_perguntas],
|
| 89 |
+
outputs=[output_res, output_model, file_download]
|
| 90 |
+
)
|
| 91 |
+
|
| 92 |
+
btn_limpar.click(lambda: ("", "Aguardando...", None, None), outputs=[input_text, output_model, output_res, file_download])
|
| 93 |
+
|
| 94 |
+
if __name__ == "__main__":
|
| 95 |
+
demo.launch() 3. Você deve RESPONDER cada pergunta em PORTUGUÊS com base no texto clássico fornecido.
|
| 96 |
+
|
| 97 |
+
REGRAS RÍGIDAS:
|
| 98 |
+
- Mantenha o texto original (Grego/Latim) intacto.
|
| 99 |
+
- Formato da resposta:
|
| 100 |
+
Pergunta [Tradução para Português]:
|
| 101 |
+
Resposta: [Sua análise detalhada]
|
| 102 |
+
|
| 103 |
+
PROTOCOLO ORIGINAL (INGLÊS):
|
| 104 |
+
{perguntas_guia_ingles}
|
| 105 |
+
|
| 106 |
+
TEXTO ORIGINAL PARA ANÁLISE:
|
| 107 |
+
{texto_usuario}
|
| 108 |
+
"""
|
| 109 |
+
|
| 110 |
resposta_ia, modelo_vencedor = call_openrouter(prompt_completo, modo)
|
| 111 |
|
| 112 |
# Criamos a exibição final
|