AniseF commited on
Commit
50bda4c
·
verified ·
1 Parent(s): 61a03c8

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +36 -214
app.py CHANGED
@@ -1,228 +1,50 @@
1
  import gradio as gr
2
- import os
3
- from utils import get_doc_content, call_openrouter
4
- from config import DOCS
5
 
 
6
  custom_css = """
7
- /* 1. Importação da Fonte (Estilo Google Sans) */
8
- @import url('https://fonts.googleapis.com/css2?family=Alegreya+Sans:ital,wght@400;700&display=swap');
9
-
10
- :root, .gradio-container, * {
11
- font-family: 'Alegreya Sans', sans-serif !important;
12
- }
13
-
14
- /* 2. O TÍTULO DA SANFONA (Accordion) */
15
- /* Miramos na classe .label-wrap que você encontrou na inspeção */
16
- .label-wrap,
17
- .label-wrap span,
18
- button.label-wrap {
19
- font-size: 22px !important;
20
- font-weight: bold !important;
21
- color: #2d2d2d !important;
22
- }
23
-
24
- /* 3. O CONTEÚDO DENTRO DA SANFONA */
25
- /* Miramos na classe .prose que envolve a lista de modelos */
26
- .prose ul,
27
- .prose li,
28
- .prose p {
29
- font-size: 20px !important;
30
- line-height: 1.5 !important;
31
- color: #444 !important;
32
- }
33
-
34
- /* 4. OUTROS ELEMENTOS (Labels, Botões, etc) */
35
-
36
- /* Unifica o tamanho de todos os títulos de componentes */
37
- label span,
38
- [data-testid="block-info"] {
39
- font-size: 22px !important;
40
- font-weight: bold !important;
41
- color: #2d2d2d !important;
42
- /* Adiciona um pequeno espaço entre o título e as opções */
43
- margin-bottom: 10px !important;
44
- display: block !important;
45
- }
46
-
47
- /* Garante que o texto dentro das opções do Radio também seja legível */
48
- .svelte-1bx8sav span {
49
- font-size: 18px !important;
50
- }
51
-
52
-
53
- button.primary, button.secondary { font-size: 20px !important; font-weight: bold !important; }
54
-
55
- /* 5. ÍCONE (A setinha ou o 'i') */
56
- .icon.svelte-1w6vloh, .icon {
57
- transform: scale(1.5) !important;
58
- }
59
- /* 1. Melhora o contraste da opção selecionada no Radio */
60
- .selected.svelte-1bx8sav,
61
- .selected {
62
- background-color: #2b5797 !important; /* Um azul mais nobre */
63
- border-color: #1a3a5f !important;
64
- }
65
-
66
- /* 2. FORÇA a cor do texto para BRANCO quando selecionado */
67
- .selected span,
68
- .selected input + span {
69
- color: white !important;
70
- font-weight: bold !important;
71
- }
72
-
73
- /* 3. Estilo para as opções NÃO selecionadas (fundo claro) */
74
- label.svelte-1bx8sav {
75
- background-color: #f5f5f5 !important;
76
- color: #2d2d2d !important;
77
- border: 1px solid #ddd !important;
78
- transition: all 0.2s ease;
79
- }
80
-
81
- /* 4. Efeito de "hover" (passar o mouse) */
82
- label.svelte-1bx8sav:hover {
83
- background-color: #e8e8e8 !important;
84
- }
85
-
86
- /* 1. Opções dentro do menu suspenso (Dropdown) */
87
- .item.svelte-1hfxrpf,
88
- .option,
89
- ul.options li {
90
- font-weight: bold !important;
91
- font-size: 18px !important;
92
- color: #2d2d2d !important;
93
- }
94
-
95
- /* 2. Quando a opção está selecionada ou com o mouse em cima */
96
- .item.selected.svelte-1hfxrpf,
97
- .item:hover {
98
- background-color: #2b5797 !important; /* Mesmo azul do Radio para harmonia */
99
- color: white !important; /* Letras brancas para contraste total */
100
- }
101
-
102
- /* 3. O texto que fica visível no botão do Dropdown após selecionar */
103
- .secondary-wrap input {
104
- font-weight: bold !important;
105
- font-size: 18px !important;
106
- color: #2d2d2d !important;
107
- }
108
-
109
- /* 1. Aumenta o texto que o usuário digita (Input) */
110
- textarea,
111
- .input-container textarea {
112
- font-size: 22px !important;
113
- line-height: 1.6 !important;
114
- font-family: 'Alegreya Sans', sans-serif !important;
115
- color: #2d2d2d !important;
116
- }
117
-
118
- /* 2. Aumenta o texto da análise gerada (Output) */
119
- /* O Gradio usa 'disabled' ou 'interactive-false' para a caixa de saída */
120
- textarea:disabled,
121
- [data-testid="textbox"]:disabled {
122
- font-size: 22px !important;
123
- line-height: 1.6 !important;
124
- font-family: 'Alegreya Sans', sans-serif !important;
125
- color: #1a1a1a !important; /* Um pouco mais escuro para facilitar a leitura */
126
- -webkit-text-fill-color: #1a1a1a !important; /* Necessário para alguns navegadores */
127
- opacity: 1 !important; /* Remove o aspecto acinzentado de 'desabilitado' */
128
- }
129
-
130
- /* 3. Garante que o placeholder (ex: "Insira o texto...") também seja legível */
131
- ::placeholder {
132
- font-size: 20px !important;
133
- opacity: 0.7;
134
- }
135
-
136
  """
137
 
138
- # 2. FUNÇÃO PARA SALVAR O TXT
139
- def salvar_txt(conteudo):
140
- if not conteudo:
141
- return None
142
- file_path = "analise_classica.txt"
143
- with open(file_path, "w", encoding="utf-8") as f:
144
- f.write(conteudo)
145
- return file_path
146
-
147
- # 3. FUNÇÃO PRINCIPAL
148
- def processar_analise(texto_usuario, modo, categoria_pergunta):
149
- if not texto_usuario.strip():
150
- return "Por favor, insira um texto.", "Aguardando...", None
151
-
152
- url = DOCS.get(categoria_pergunta)
153
- perguntas_guia_ingles = get_doc_content(url)
154
-
155
- # Prompt REFORÇADO para garantir tradução em modelos menores
156
- prompt_completo = f"""
157
- ### INSTRUÇÃO CRÍTICA DE IDIOMA ###
158
- Toda a sua resposta DEVE ser em PORTUGUÊS.
159
- Você deve traduzir as perguntas abaixo do Inglês para o Português antes de respondê-las.
160
-
161
- ### TAREFA ###
162
- 1. Leia o PROTOCOLO em inglês.
163
- 2. TRADUZA cada pergunta para o Português.
164
- 3. RESPONDA cada pergunta em Português analisando o TEXTO fornecido.
165
- 4. Mantenha os termos em Grego/Latim originais e intactos.
166
-
167
- ### PROTOCOLO ORIGINAL (INGLÊS) ###
168
- {perguntas_guia_ingles}
169
-
170
- ### TEXTO ORIGINAL PARA ANÁLISE ###
171
- {texto_usuario}
172
 
173
- ### FORMATO DESEJADO ###
174
- Pergunta: (Sua tradução aqui)
175
- Resposta: (Sua análise detalhada em português)
176
- """
177
 
178
- resposta_ia, modelo_vencedor = call_openrouter(prompt_completo, modo)
179
- exibicao_final = f"--- RELATORIO DE ANALISE ---\n\n{resposta_ia}"
180
- caminho_arquivo = salvar_txt(exibicao_final)
181
-
182
- return exibicao_final, f"Modelo: {modelo_vencedor}", caminho_arquivo
 
183
 
184
- # 4. INTERFACE
185
- with gr.Blocks(theme=gr.themes.Soft(), css=custom_css) as demo:
186
- gr.Markdown("# 🏛️ AI for Classics")
187
 
188
- with gr.Accordion("ℹ️ Modelos e Estratégias", open=False):
189
- gr.Markdown("""
190
- - **Alta Precisão:** Claude 3.5, GPT-4o, Gemini Pro.
191
- - **Custo-Benefício:** Gemini Flash, Command R, Mistral.
192
- """)
193
-
194
  with gr.Row():
195
- with gr.Column(scale=1):
196
- input_text = gr.Textbox(label="1. Insira o texto", lines=10)
197
- modo_radio = gr.Radio(
198
- choices=["Alta Precisão (Filológica)", "Custo-Benefício (Triagem)"],
199
- label="2. Selecione a estratégia/modelo",
200
- value="Alta Precisão (Filológico)"
201
- )
202
- cat_perguntas = gr.Dropdown(
203
- choices=["SYNTAX", "MORPHOLOGY", "SEMANTICS"],
204
- label="3. Selecione: Sintaxe, Morfologia ou Semântica",
205
- value="SYNTAX"
206
- )
207
- with gr.Row():
208
- btn_limpar = gr.Button("Limpar")
209
- btn_rodar = gr.Button("🚀 EXECUTAR", variant="primary")
210
-
211
- with gr.Column(scale=1):
212
- output_res = gr.Textbox(label="Análise Gerada", lines=18, interactive=False)
213
- output_model = gr.Label(label="Status")
214
- file_download = gr.File(label="Baixar TXT")
215
 
216
- btn_rodar.click(
217
- processar_analise,
218
- inputs=[input_text, modo_radio, cat_perguntas],
219
- outputs=[output_res, output_model, file_download]
220
- )
221
 
222
- btn_limpar.click(
223
- lambda: ("", "Aguardando...", "", None),
224
- outputs=[input_text, output_model, output_res, file_download]
 
 
 
 
 
225
  )
226
 
227
- if __name__ == "__main__":
228
- demo.launch()
 
1
  import gradio as gr
2
+ from utils import call_openrouter
 
 
3
 
4
+ # CSS para Contraste e Fontes (O que ajustamos antes)
5
  custom_css = """
6
+ textarea, .input-container textarea { font-size: 22px !important; line-height: 1.6 !important; }
7
+ .selected { background-color: #2b5797 !important; color: white !important; }
8
+ .selected span { color: white !important; font-weight: bold !important; }
9
+ .item.selected, .item:hover { background-color: #2b5797 !important; color: white !important; }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
10
  """
11
 
12
+ def process_interface(passage, mode, category):
13
+ if not passage.strip():
14
+ return "Por favor, insira um texto.", None, "Aguardando entrada..."
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
15
 
16
+ # Chama a função turbinada do utils
17
+ report, model_used = call_openrouter(passage, mode, category)
 
 
18
 
19
+ # Gera arquivo para download
20
+ file_path = "analise_completa.txt"
21
+ with open(file_path, "w", encoding="utf-8") as f:
22
+ f.write(report)
23
+
24
+ return report, file_path, f"Finalizado com: {model_used}"
25
 
26
+ with gr.Blocks(css=custom_css, theme=gr.themes.Soft()) as demo:
27
+ gr.Markdown("# 🏛️ Assistente de Análise Filológica")
 
28
 
 
 
 
 
 
 
29
  with gr.Row():
30
+ input_text = gr.Textbox(label="Passagem em Latim ou Grego", lines=8)
31
+
32
+ with gr.Row():
33
+ radio_mode = gr.Radio(["Alta Precisão (Filológico)", "Custo-Benefício"],
34
+ label="Modo de Operação", value="Alta Precisão (Filológico)")
35
+ radio_cat = gr.Radio(["Syntax", "Morphology", "Semantics"],
36
+ label="Protocolo de Análise", value="Syntax")
 
 
 
 
 
 
 
 
 
 
 
 
 
37
 
38
+ btn = gr.Button("Gerar Análise Completa", variant="primary")
 
 
 
 
39
 
40
+ output_report = gr.Textbox(label="Relatório de Análise", lines=15)
41
+ output_file = gr.File(label="Baixar Relatório (.txt)")
42
+ status = gr.Markdown("Pronto para iniciar.")
43
+
44
+ btn.click(
45
+ fn=process_interface,
46
+ inputs=[input_text, radio_mode, radio_cat],
47
+ outputs=[output_report, output_file, status]
48
  )
49
 
50
+ demo.launch()