Spaces:
Sleeping
Sleeping
| import gradio as gr | |
| from utils import call_openrouter | |
| # app.py | |
| custom_css = """ | |
| @import url('https://fonts.googleapis.com/css2?family=Alegreya+Sans:ital,wght@0,400;0,700;1,400;1,700&display=swap'); | |
| /* 1. Aplicação Global com tamanho aumentado */ | |
| body, .gradio-container, .gr-button, .gr-form, p, span { | |
| font-family: 'Alegreya Sans', sans-serif !important; | |
| font-size: 20px !important; /* Tamanho base para labels e botões */ | |
| } | |
| /* 2. Foco total na legibilidade do Input e Output */ | |
| textarea, | |
| .input-container textarea, | |
| .output-class textarea, | |
| [data-testid="textbox"] { | |
| font-family: 'Alegreya Sans', sans-serif !important; | |
| font-size: 24px !important; /* Tamanho generoso para o Grego e a Análise */ | |
| line-height: 1.5 !important; | |
| padding: 15px !important; | |
| } | |
| /* 3. Ajuste do Markdown (o relatório gerado) */ | |
| .prose, .markdown-text, .prose p { | |
| font-family: 'Alegreya Sans', sans-serif !important; | |
| font-size: 22px !important; | |
| line-height: 1.6 !important; | |
| } | |
| /* 4. Títulos do Relatório */ | |
| .prose h1, .prose h2, .prose h3 { | |
| font-family: 'Alegreya Sans', sans-serif !important; | |
| font-weight: 700 !important; | |
| color: #2b5797 !important; | |
| } | |
| /* 5. Cores de seleção do Thomas (preservadas) */ | |
| .selected { background-color: #2b5797 !important; color: white !important; } | |
| .selected span { color: white !important; font-weight: bold !important; } | |
| .item.selected, .item:hover { background-color: #2b5797 !important; color: white !important; } | |
| """ | |
| # 2. Definição das listas de modelos para exibição | |
| MODELS_A = ["anthropic/claude-3.5-sonnet", "openai/gpt-4o", "google/gemini-pro-1.5"] | |
| MODELS_B = ["google/gemini-flash-1.5", "mistralai/mistral-7b-instruct", "cohere/command-r"] | |
| # 3. Função que atualiza a lista de modelos na tela | |
| def update_model_display(mode): | |
| chain = MODELS_A if "Alta" in mode else MODELS_B | |
| display_text = "### 🔗 Cadeia de Modelos Ativa:\n" | |
| for m in chain: | |
| display_text += f"- `{m}`\n" | |
| return display_text | |
| # 4. Função que processa a interface (O QUE ESTAVA FALTANDO) | |
| def process_interface(passage, mode, category): | |
| if not passage.strip(): | |
| return "Por favor, insira um texto.", None, "Aguardando entrada..." | |
| # Chama a função turbinada do utils | |
| report, model_used = call_openrouter(passage, mode, category) | |
| # Gera arquivo para download | |
| file_path = "analise_completa.txt" | |
| with open(file_path, "w", encoding="utf-8") as f: | |
| f.write(report) | |
| return report, file_path, f"Finalizado com: {model_used}" | |
| # 5. Construção da Interface Gradio | |
| with gr.Blocks(css=custom_css, theme=gr.themes.Soft()) as demo: | |
| gr.Markdown("# 🏛️ Assistente de Análise Filológica") | |
| with gr.Row(): | |
| input_text = gr.Textbox(label="Passagem em Latim ou Grego", lines=8) | |
| with gr.Row(): | |
| with gr.Column(): | |
| radio_mode = gr.Radio(["Alta Precisão (Filológica)", "Custo-Benefício"], | |
| label="Modo de Operação", value="Alta Precisão (Filológica)") | |
| model_info_display = gr.Markdown(update_model_display("Alta Precisão (Filológica)")) | |
| radio_cat = gr.Radio(["Syntax", "Morphology", "Semantics"], | |
| label="Protocolo de Análise", value="Syntax") | |
| # Evento para mudar a lista de modelos quando o usuário trocar o Radio | |
| radio_mode.change(fn=update_model_display, inputs=radio_mode, outputs=model_info_display) | |
| btn = gr.Button("Gerar Análise Completa", variant="primary") | |
| output_report = gr.Textbox(label="Relatório de Análise", lines=15) | |
| output_file = gr.File(label="Baixar Relatório (.txt)") | |
| status = gr.Markdown("Pronto para iniciar.") | |
| # Conexão do botão com a função definida no item 4 | |
| btn.click( | |
| fn=process_interface, | |
| inputs=[input_text, radio_mode, radio_cat], | |
| outputs=[output_report, output_file, status] | |
| ) | |
| if __name__ == "__main__": | |
| demo.launch() |