Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -1,4 +1,3 @@
|
|
1 |
-
import gradio as gr
|
2 |
import requests
|
3 |
import os
|
4 |
import json
|
@@ -130,17 +129,6 @@ class HuggingFaceAPIClient:
|
|
130 |
# Inicializar cliente da API
|
131 |
api_client = HuggingFaceAPIClient(HF_TOKEN)
|
132 |
|
133 |
-
def escape_html(text: str) -> str:
|
134 |
-
"""Escapa caracteres especiais HTML para exibi莽茫o segura."""
|
135 |
-
html_escape_table = {
|
136 |
-
"&": "&",
|
137 |
-
"<": "<",
|
138 |
-
">": ">",
|
139 |
-
'"': """,
|
140 |
-
"'": "'"
|
141 |
-
}
|
142 |
-
return "".join(html_escape_table.get(c, c) for c in text)
|
143 |
-
|
144 |
def formatar_resposta_com_codigo(resposta: str) -> str:
|
145 |
"""Formata a resposta destacando c贸digos em blocos separados"""
|
146 |
if not resposta:
|
@@ -149,7 +137,7 @@ def formatar_resposta_com_codigo(resposta: str) -> str:
|
|
149 |
# Detecta blocos de c贸digo com ```
|
150 |
resposta_formatada = re.sub(
|
151 |
r'```(\w+)?\n(.*?)\n```',
|
152 |
-
|
153 |
resposta,
|
154 |
flags=re.DOTALL
|
155 |
)
|
@@ -157,7 +145,7 @@ def formatar_resposta_com_codigo(resposta: str) -> str:
|
|
157 |
# Detecta c贸digo inline com `
|
158 |
resposta_formatada = re.sub(
|
159 |
r'`([^`]+)`',
|
160 |
-
|
161 |
resposta_formatada
|
162 |
)
|
163 |
|
@@ -259,8 +247,8 @@ css_customizado = """
|
|
259 |
}
|
260 |
|
261 |
.resposta-container {
|
262 |
-
background-color: #ffffff !important;
|
263 |
-
color: #1a1a1a !important;
|
264 |
border: 1px solid #e0e0e0 !important;
|
265 |
border-radius: 20px !important;
|
266 |
padding: 20px !important;
|
@@ -269,8 +257,8 @@ css_customizado = """
|
|
269 |
}
|
270 |
|
271 |
.resposta-container pre code {
|
272 |
-
color: #1a1a1a !important;
|
273 |
-
background-color: #f8f9fa !important;
|
274 |
}
|
275 |
|
276 |
.pergunta-container {
|
@@ -287,24 +275,6 @@ css_customizado = """
|
|
287 |
margin-bottom: 20px !important;
|
288 |
text-align: center !important;
|
289 |
}
|
290 |
-
|
291 |
-
.modelo-select {
|
292 |
-
background-color: #f0f8ff !important;
|
293 |
-
color: #1a1a1a !important;
|
294 |
-
border: 1px solid #e0e0e0 !important;
|
295 |
-
border-radius: 8px !important;
|
296 |
-
padding: 10px !important;
|
297 |
-
font-size: 14px !important;
|
298 |
-
width: 100% !important;
|
299 |
-
margin-top: 10px !important;
|
300 |
-
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, 'Open Sans', 'Helvetica Neue', sans-serif !important;
|
301 |
-
}
|
302 |
-
|
303 |
-
.modelo-select:focus {
|
304 |
-
outline: none !important;
|
305 |
-
border-color: #667eea !important;
|
306 |
-
box-shadow: 0 0 5px rgba(102, 126, 234, 0.5) !important;
|
307 |
-
}
|
308 |
"""
|
309 |
|
310 |
# Interface Gradio
|
@@ -334,22 +304,18 @@ with gr.Blocks(
|
|
334 |
elem_classes="pergunta-container"
|
335 |
)
|
336 |
|
337 |
-
|
338 |
-
|
339 |
-
value=
|
340 |
-
|
341 |
-
|
342 |
-
</select>
|
343 |
-
""",
|
344 |
-
label=""
|
345 |
)
|
346 |
|
347 |
with gr.Row():
|
348 |
-
botao_perguntar.
|
349 |
-
|
350 |
-
|
351 |
-
|
352 |
-
show_progress=True
|
353 |
)
|
354 |
botao_testar = gr.Button(
|
355 |
"馃攳 Testar Modelos",
|
|
|
|
|
1 |
import requests
|
2 |
import os
|
3 |
import json
|
|
|
129 |
# Inicializar cliente da API
|
130 |
api_client = HuggingFaceAPIClient(HF_TOKEN)
|
131 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
132 |
def formatar_resposta_com_codigo(resposta: str) -> str:
|
133 |
"""Formata a resposta destacando c贸digos em blocos separados"""
|
134 |
if not resposta:
|
|
|
137 |
# Detecta blocos de c贸digo com ```
|
138 |
resposta_formatada = re.sub(
|
139 |
r'```(\w+)?\n(.*?)\n```',
|
140 |
+
r'<div style="background-color: #f8f9fa; color: #1a1a1a; border: 1px solid #e9ecef; border-radius: 8px; padding: 15px; margin: 10px 0; font-family: Monaco, Consolas, monospace; overflow-x: auto;"><strong style="color: #1a1a1a;">馃捇 C贸digo:</strong><br><pre style="color: #1a1a1a; margin: 5px 0; white-space: pre-wrap; word-wrap: break-word;"><code>\2</code></pre></div>',
|
141 |
resposta,
|
142 |
flags=re.DOTALL
|
143 |
)
|
|
|
145 |
# Detecta c贸digo inline com `
|
146 |
resposta_formatada = re.sub(
|
147 |
r'`([^`]+)`',
|
148 |
+
r'<code style="background-color: #f1f3f4; color: #1a1a1a; padding: 2px 4px; border-radius: 4px; font-family: Monaco, Consolas, monospace;">\1</code>',
|
149 |
resposta_formatada
|
150 |
)
|
151 |
|
|
|
247 |
}
|
248 |
|
249 |
.resposta-container {
|
250 |
+
background-color: #ffffff !important; /* Always light background */
|
251 |
+
color: #1a1a1a !important; /* Always dark text */
|
252 |
border: 1px solid #e0e0e0 !important;
|
253 |
border-radius: 20px !important;
|
254 |
padding: 20px !important;
|
|
|
257 |
}
|
258 |
|
259 |
.resposta-container pre code {
|
260 |
+
color: #1a1a1a !important; /* Ensure code text is dark */
|
261 |
+
background-color: #f8f9fa !important; /* Light background for code */
|
262 |
}
|
263 |
|
264 |
.pergunta-container {
|
|
|
275 |
margin-bottom: 20px !important;
|
276 |
text-align: center !important;
|
277 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
278 |
"""
|
279 |
|
280 |
# Interface Gradio
|
|
|
304 |
elem_classes="pergunta-container"
|
305 |
)
|
306 |
|
307 |
+
modelo_select = gr.Dropdown(
|
308 |
+
choices=list(MODELS.keys()),
|
309 |
+
value="phi3-mini",
|
310 |
+
label="馃 Modelo de IA",
|
311 |
+
info="Escolha o modelo para responder sua pergunta"
|
|
|
|
|
|
|
312 |
)
|
313 |
|
314 |
with gr.Row():
|
315 |
+
botao_perguntar = gr.Button(
|
316 |
+
"馃 Perguntar ao Dr. Aldo",
|
317 |
+
variant="primary",
|
318 |
+
size="lg"
|
|
|
319 |
)
|
320 |
botao_testar = gr.Button(
|
321 |
"馃攳 Testar Modelos",
|