aldohenrique commited on
Commit
53cefbb
verified
1 Parent(s): db2f74e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -49
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
- "<": "&lt;",
138
- ">": "&gt;",
139
- '"': "&quot;",
140
- "'": "&#x27;"
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
- lambda m: f'<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>{escape_html(m.group(2))}</code></pre></div>',
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
- lambda m: f'<code style="background-color: #f1f3f4; color: #1a1a1a; padding: 2px 4px; border-radius: 4px; font-family: Monaco, Consolas, monospace;">{escape_html(m.group(1))}</code>',
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
- # Renderiza um <select> com HTML
338
- modelo_select = gr.HTML(
339
- value=f"""
340
- <select id="modelo-select" class="modelo-select">
341
- {''.join(f'<option value="{key}" {"selected" if key == "phi3-mini" else ""}>{key}</option>' for key in MODELS.keys())}
342
- </select>
343
- """,
344
- label=""
345
  )
346
 
347
  with gr.Row():
348
- botao_perguntar.click(
349
- fn=responder_como_aldo,
350
- inputs=[entrada, modelo_select],
351
- outputs=saida,
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",