Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -7,7 +7,7 @@ from datetime import datetime
|
|
| 7 |
TITLE = "🏦 CREDIFAST - SISTEMA DE ANÁLISE DE RISCO"
|
| 8 |
DESC = "Prova Final SIEP | Emily Valkiria Gonçalves Sousa | 231034500 | Professor: João Gabriel"
|
| 9 |
|
| 10 |
-
# ========== DADOS SIMPLIFICADOS
|
| 11 |
def gerar_dados_simples():
|
| 12 |
np.random.seed(42)
|
| 13 |
n = 500
|
|
@@ -21,17 +21,11 @@ def gerar_dados_simples():
|
|
| 21 |
'status': np.random.choice([0, 1], n, p=[0.8, 0.2])
|
| 22 |
})
|
| 23 |
|
| 24 |
-
# Calcular risco de forma SIMPLES (sem condicionais complexos)
|
| 25 |
-
dados['endividamento'] = dados['emprestimo'] / dados['renda']
|
| 26 |
-
|
| 27 |
-
# Score de risco simples
|
| 28 |
dados['risco'] = (
|
| 29 |
((850 - dados['score']) / 550 * 40) +
|
| 30 |
-
(dados['
|
| 31 |
-
((70 - dados['idade']) * 0.3).clip(0, 30)
|
| 32 |
).clip(0, 100)
|
| 33 |
|
| 34 |
-
# Classificação
|
| 35 |
dados['classificacao'] = pd.cut(dados['risco'],
|
| 36 |
bins=[0, 30, 60, 100],
|
| 37 |
labels=['Baixo', 'Médio', 'Alto'])
|
|
@@ -52,13 +46,12 @@ def criar_dashboard(filtro_risco="Todos"):
|
|
| 52 |
risco_medio = df_filtrado['risco'].mean()
|
| 53 |
renda_media = df_filtrado['renda'].mean()
|
| 54 |
|
| 55 |
-
# Contagem por classificação
|
| 56 |
baixo = len(df_filtrado[df_filtrado['classificacao'] == 'Baixo'])
|
| 57 |
medio = len(df_filtrado[df_filtrado['classificacao'] == 'Médio'])
|
| 58 |
alto = len(df_filtrado[df_filtrado['classificacao'] == 'Alto'])
|
| 59 |
|
| 60 |
html = f"""
|
| 61 |
-
<div style="font-family: Arial, sans-serif; max-width: 1200px; margin: auto;">
|
| 62 |
<!-- HEADER -->
|
| 63 |
<div style="background: linear-gradient(135deg, #0f172a, #1e293b); color: white; padding: 25px; border-radius: 15px; margin-bottom: 20px; text-align: center;">
|
| 64 |
<h1 style="margin: 0;">{TITLE}</h1>
|
|
@@ -67,15 +60,10 @@ def criar_dashboard(filtro_risco="Todos"):
|
|
| 67 |
</div>
|
| 68 |
|
| 69 |
<!-- FILTRO ATIVO -->
|
| 70 |
-
<div style="background: white; padding: 15px; border-radius: 10px; margin-bottom: 20px; box-shadow: 0 2px 8px rgba(0,0,0,0.1);
|
| 71 |
-
<
|
| 72 |
-
|
| 73 |
-
|
| 74 |
-
<strong>Taxa Bad:</strong> {taxa_bad:.1f}%
|
| 75 |
-
</div>
|
| 76 |
-
<div style="color: #666; font-size: 14px;">
|
| 77 |
-
Prova Final SIEP - Emily Valkiria (231034500)
|
| 78 |
-
</div>
|
| 79 |
</div>
|
| 80 |
|
| 81 |
<!-- KPI CARDS -->
|
|
@@ -84,38 +72,31 @@ def criar_dashboard(filtro_risco="Todos"):
|
|
| 84 |
<div style="font-size: 30px; margin-bottom: 10px;">👥</div>
|
| 85 |
<div style="font-size: 14px;">CLIENTES</div>
|
| 86 |
<div style="font-size: 32px; font-weight: 800; margin: 10px 0;">{total:,}</div>
|
| 87 |
-
<div style="font-size: 12px; opacity: 0.9;">Ativos na base</div>
|
| 88 |
</div>
|
| 89 |
|
| 90 |
<div style="background: linear-gradient(135deg, #dc2626, #ef4444); color: white; padding: 20px; border-radius: 10px; text-align: center;">
|
| 91 |
<div style="font-size: 30px; margin-bottom: 10px;">⚠️</div>
|
| 92 |
<div style="font-size: 14px;">TAXA BAD</div>
|
| 93 |
<div style="font-size: 32px; font-weight: 800; margin: 10px 0;">{taxa_bad:.1f}%</div>
|
| 94 |
-
<div style="font-size: 12px; opacity: 0.9;">Default/Charge Off</div>
|
| 95 |
</div>
|
| 96 |
|
| 97 |
<div style="background: linear-gradient(135deg, #d97706, #f59e0b); color: white; padding: 20px; border-radius: 10px; text-align: center;">
|
| 98 |
<div style="font-size: 30px; margin-bottom: 10px;">📊</div>
|
| 99 |
<div style="font-size: 14px;">RISCO MÉDIO</div>
|
| 100 |
<div style="font-size: 32px; font-weight: 800; margin: 10px 0;">{risco_medio:.1f}</div>
|
| 101 |
-
<div style="font-size: 12px; opacity: 0.9;">Score 0-100</div>
|
| 102 |
</div>
|
| 103 |
|
| 104 |
<div style="background: linear-gradient(135deg, #059669, #10b981); color: white; padding: 20px; border-radius: 10px; text-align: center;">
|
| 105 |
<div style="font-size: 30px; margin-bottom: 10px;">💰</div>
|
| 106 |
<div style="font-size: 14px;">RENDA MÉDIA</div>
|
| 107 |
<div style="font-size: 32px; font-weight: 800; margin: 10px 0;">R$ {renda_media:,.0f}</div>
|
| 108 |
-
<div style="font-size: 12px; opacity: 0.9;">Anual</div>
|
| 109 |
</div>
|
| 110 |
</div>
|
| 111 |
|
| 112 |
-
<!-- DISTRIBUIÇÃO
|
| 113 |
<div style="background: white; padding: 25px; border-radius: 10px; margin: 20px 0; box-shadow: 0 2px 8px rgba(0,0,0,0.1);">
|
| 114 |
-
<h3 style="margin: 0 0 20px 0; color: #1e293b;
|
| 115 |
-
<span>📊</span> DISTRIBUIÇÃO DE RISCO
|
| 116 |
-
</h3>
|
| 117 |
|
| 118 |
-
<!-- Barras de distribuição -->
|
| 119 |
<div style="display: flex; height: 60px; border-radius: 8px; overflow: hidden; margin-bottom: 20px;">
|
| 120 |
<div style="background: #00C853; flex: {baixo}; display: flex; align-items: center; justify-content: center; color: white; font-weight: bold; font-size: 18px;">
|
| 121 |
{baixo}
|
|
@@ -128,22 +109,18 @@ def criar_dashboard(filtro_risco="Todos"):
|
|
| 128 |
</div>
|
| 129 |
</div>
|
| 130 |
|
| 131 |
-
<!-- Legenda -->
|
| 132 |
<div style="display: flex; justify-content: space-around; text-align: center;">
|
| 133 |
<div>
|
| 134 |
-
<div style="width: 20px; height: 20px; background: #00C853; border-radius: 50%; margin: 0 auto 5px;"></div>
|
| 135 |
<div style="font-weight: bold; color: #1e293b;">BAIXO</div>
|
| 136 |
<div style="font-size: 24px; font-weight: 800; color: #00C853;">{baixo}</div>
|
| 137 |
<div style="font-size: 12px; color: #666;">{(baixo/total*100 if total>0 else 0):.1f}%</div>
|
| 138 |
</div>
|
| 139 |
<div>
|
| 140 |
-
<div style="width: 20px; height: 20px; background: #FF9800; border-radius: 50%; margin: 0 auto 5px;"></div>
|
| 141 |
<div style="font-weight: bold; color: #1e293b;">MÉDIO</div>
|
| 142 |
<div style="font-size: 24px; font-weight: 800; color: #FF9800;">{medio}</div>
|
| 143 |
<div style="font-size: 12px; color: #666;">{(medio/total*100 if total>0 else 0):.1f}%</div>
|
| 144 |
</div>
|
| 145 |
<div>
|
| 146 |
-
<div style="width: 20px; height: 20px; background: #F44336; border-radius: 50%; margin: 0 auto 5px;"></div>
|
| 147 |
<div style="font-weight: bold; color: #1e293b;">ALTO</div>
|
| 148 |
<div style="font-size: 24px; font-weight: 800; color: #F44336;">{alto}</div>
|
| 149 |
<div style="font-size: 12px; color: #666;">{(alto/total*100 if total>0 else 0):.1f}%</div>
|
|
@@ -151,78 +128,52 @@ def criar_dashboard(filtro_risco="Todos"):
|
|
| 151 |
</div>
|
| 152 |
</div>
|
| 153 |
|
| 154 |
-
<!--
|
| 155 |
<div style="background: white; padding: 25px; border-radius: 10px; margin: 20px 0; box-shadow: 0 2px 8px rgba(0,0,0,0.1);">
|
| 156 |
-
<h3 style="margin: 0 0 20px 0; color: #1e293b;
|
| 157 |
-
<span>🤖</span> COMPARAÇÃO DE MODELOS (PROVA SIEP)
|
| 158 |
-
</h3>
|
| 159 |
|
| 160 |
-
<
|
| 161 |
-
|
| 162 |
-
|
| 163 |
-
|
| 164 |
-
|
| 165 |
-
<
|
| 166 |
-
|
| 167 |
-
|
| 168 |
-
|
| 169 |
-
|
| 170 |
-
|
| 171 |
-
</
|
| 172 |
-
<
|
| 173 |
-
|
| 174 |
-
|
| 175 |
-
|
| 176 |
-
|
| 177 |
-
|
| 178 |
-
|
| 179 |
-
|
| 180 |
-
|
| 181 |
-
|
| 182 |
-
|
| 183 |
-
|
| 184 |
-
|
| 185 |
-
|
| 186 |
-
|
| 187 |
-
|
| 188 |
-
|
| 189 |
-
|
| 190 |
-
|
| 191 |
-
|
| 192 |
-
|
| 193 |
-
|
| 194 |
-
|
| 195 |
-
|
| 196 |
-
<td style="padding: 10px; text-align: center;"><span style="color: #F44336;">🔴 REGULAR</span></td>
|
| 197 |
-
</tr>
|
| 198 |
-
</tbody>
|
| 199 |
-
</table>
|
| 200 |
-
</div>
|
| 201 |
-
|
| 202 |
-
<!-- Recomendações -->
|
| 203 |
-
<div style="background: #f8f9fa; padding: 15px; border-radius: 8px;">
|
| 204 |
-
<h4 style="margin: 0 0 10px 0; color: #1e293b;">📋 RECOMENDAÇÕES (PROVA)</h4>
|
| 205 |
-
<div style="background: #e8f5e9; padding: 10px; border-radius: 6px; margin-bottom: 10px;">
|
| 206 |
-
<strong>1. Balanceamento SMOTE:</strong> Corrigir proporção 80/20
|
| 207 |
-
</div>
|
| 208 |
-
<div style="background: #fff3e0; padding: 10px; border-radius: 6px; margin-bottom: 10px;">
|
| 209 |
-
<strong>2. Análise SHAP:</strong> Explicabilidade das decisões
|
| 210 |
-
</div>
|
| 211 |
-
<div style="background: #e3f2fd; padding: 10px; border-radius: 6px; margin-bottom: 10px;">
|
| 212 |
-
<strong>3. Clusterização:</strong> KMeans + DBSCAN para outliers
|
| 213 |
-
</div>
|
| 214 |
-
<div style="background: #fce4ec; padding: 10px; border-radius: 6px;">
|
| 215 |
-
<strong>4. Políticas de Crédito:</strong> Baseadas em evidências
|
| 216 |
-
</div>
|
| 217 |
-
</div>
|
| 218 |
-
</div>
|
| 219 |
</div>
|
| 220 |
|
| 221 |
<!-- FOOTER -->
|
| 222 |
<div style="text-align: center; color: #666; margin-top: 30px; padding-top: 20px; border-top: 1px solid #e0e0e0;">
|
| 223 |
<p><strong>Universidade de Brasília - UnB | Faculdade de Tecnologia - FT</strong></p>
|
| 224 |
-
<p>
|
| 225 |
-
<p>Aluna: Emily Valkiria Gonçalves Sousa | Matrícula: 231034500</p>
|
| 226 |
<p>Professor: João Gabriel de Moraes Souza | Data: 04/12/2025</p>
|
| 227 |
</div>
|
| 228 |
</div>
|
|
@@ -236,62 +187,35 @@ def analisar_cliente(idade, renda, score, valor):
|
|
| 236 |
|
| 237 |
if risco < 30:
|
| 238 |
html = f"""
|
| 239 |
-
<div style="background: #e8f5e9; padding:
|
| 240 |
-
<
|
| 241 |
-
|
| 242 |
-
|
| 243 |
-
|
| 244 |
-
<p style="margin: 5px 0; font-size: 18px;">Score: <strong>{risco:.1f}/100</strong></p>
|
| 245 |
-
</div>
|
| 246 |
-
</div>
|
| 247 |
-
<div style="background: white; padding: 15px; border-radius: 8px;">
|
| 248 |
-
<h4 style="margin-top: 0; color: #333;">✅ RECOMENDAÇÃO DO SISTEMA</h4>
|
| 249 |
-
<p style="font-size: 18px; color: #1b5e20; font-weight: bold;">APROVAÇÃO AUTOMÁTICA</p>
|
| 250 |
-
<p>Taxa sugerida: 8.5% - 12.5% | Prazo: até 48 meses</p>
|
| 251 |
-
<p><strong>Condições:</strong> Sem restrições adicionais</p>
|
| 252 |
-
</div>
|
| 253 |
</div>
|
| 254 |
"""
|
| 255 |
elif risco < 60:
|
| 256 |
html = f"""
|
| 257 |
-
<div style="background: #fff3e0; padding:
|
| 258 |
-
<
|
| 259 |
-
|
| 260 |
-
|
| 261 |
-
|
| 262 |
-
<p style="margin: 5px 0; font-size: 18px;">Score: <strong>{risco:.1f}/100</strong></p>
|
| 263 |
-
</div>
|
| 264 |
-
</div>
|
| 265 |
-
<div style="background: white; padding: 15px; border-radius: 8px;">
|
| 266 |
-
<h4 style="margin-top: 0; color: #333;">⚠️ RECOMENDAÇÃO DO SISTEMA</h4>
|
| 267 |
-
<p style="font-size: 18px; color: #e65100; font-weight: bold;">ANÁLISE SUPERVISIONADA</p>
|
| 268 |
-
<p>Taxa sugerida: 14.5% - 18.5% | Documentação adicional necessária</p>
|
| 269 |
-
<p><strong>Condições:</strong> Comprovar renda e endividamento</p>
|
| 270 |
-
</div>
|
| 271 |
</div>
|
| 272 |
"""
|
| 273 |
else:
|
| 274 |
html = f"""
|
| 275 |
-
<div style="background: #ffebee; padding:
|
| 276 |
-
<
|
| 277 |
-
|
| 278 |
-
|
| 279 |
-
|
| 280 |
-
<p style="margin: 5px 0; font-size: 18px;">Score: <strong>{risco:.1f}/100</strong></p>
|
| 281 |
-
</div>
|
| 282 |
-
</div>
|
| 283 |
-
<div style="background: white; padding: 15px; border-radius: 8px;">
|
| 284 |
-
<h4 style="margin-top: 0; color: #333;">❌ RECOMENDAÇÃO DO SISTEMA</h4>
|
| 285 |
-
<p style="font-size: 18px; color: #b71c1c; font-weight: bold;">REPROVAÇÃO RECOMENDADA</p>
|
| 286 |
-
<p>Exigir garantias reais ou considerar reprovação</p>
|
| 287 |
-
<p><strong>Condições:</strong> Avalista ou garantia necessária</p>
|
| 288 |
-
</div>
|
| 289 |
</div>
|
| 290 |
"""
|
| 291 |
return html
|
| 292 |
|
| 293 |
# ========== INTERFACE GRADIO ==========
|
| 294 |
-
with gr.Blocks(title=TITLE
|
| 295 |
|
| 296 |
# Header
|
| 297 |
gr.HTML(f"""
|
|
@@ -307,108 +231,88 @@ with gr.Blocks(title=TITLE, css=""".gradio-container { max-width: 1200px; margin
|
|
| 307 |
# Tabs
|
| 308 |
with gr.Tabs():
|
| 309 |
|
| 310 |
-
with gr.Tab("📊 DASHBOARD
|
| 311 |
-
gr.Markdown("### 🎛️ CONTROLES DO DASHBOARD")
|
| 312 |
-
|
| 313 |
with gr.Row():
|
| 314 |
filtro_risco = gr.Dropdown(
|
| 315 |
["Todos", "Baixo", "Médio", "Alto"],
|
| 316 |
value="Todos",
|
| 317 |
-
label="Filtrar por
|
| 318 |
)
|
| 319 |
-
btn_atualizar = gr.Button("🔄 Atualizar
|
| 320 |
|
| 321 |
-
|
| 322 |
|
| 323 |
-
def
|
| 324 |
return criar_dashboard(risco)
|
| 325 |
|
| 326 |
-
btn_atualizar.click(
|
| 327 |
-
|
| 328 |
-
# Carregar inicialmente
|
| 329 |
-
app.load(lambda: criar_dashboard("Todos"), outputs=dashboard_output)
|
| 330 |
|
| 331 |
-
with gr.Tab("🔍 ANÁLISE
|
| 332 |
-
gr.Markdown("### 🎯 SIMULADOR DE RISCO POR CLIENTE")
|
| 333 |
-
|
| 334 |
with gr.Row():
|
| 335 |
-
with gr.Column(
|
| 336 |
-
idade = gr.Slider(18, 70, 35, label="Idade
|
| 337 |
-
renda = gr.Number(50000, label="Renda
|
| 338 |
-
score = gr.Slider(300, 850, 650, label="Score
|
| 339 |
-
valor = gr.Number(20000, label="
|
| 340 |
-
|
| 341 |
|
| 342 |
-
with gr.Column(
|
| 343 |
-
|
| 344 |
|
| 345 |
-
|
| 346 |
|
| 347 |
-
# Exemplos
|
| 348 |
-
gr.
|
| 349 |
-
|
| 350 |
-
|
| 351 |
-
|
| 352 |
-
|
| 353 |
-
|
| 354 |
-
|
| 355 |
-
|
| 356 |
-
|
| 357 |
-
|
| 358 |
-
fn=analisar_cliente,
|
| 359 |
-
label="Clique para testar diferentes perfis:"
|
| 360 |
-
)
|
| 361 |
|
| 362 |
-
with gr.Tab("📚 CONCLUSÃO
|
| 363 |
gr.Markdown("""
|
| 364 |
-
##
|
| 365 |
|
| 366 |
-
|
| 367 |
-
|
| 368 |
-
|
| 369 |
-
|
| 370 |
-
|
| 371 |
-
5. **Recomendações gerenciais** baseadas em evidências
|
| 372 |
-
6. **Clusterização** com KMeans e detecção de outliers com DBSCAN
|
| 373 |
-
|
| 374 |
-
### 🎯 RESULTADOS PRINCIPAIS:
|
| 375 |
-
- **Redução estimada na inadimplência:** 32%
|
| 376 |
-
- **Aumento na precisão das aprovações:** 18%
|
| 377 |
-
- **Melhoria no F1-Score:** 24%
|
| 378 |
-
- **ROI anual estimado:** R$ 4,3 milhões
|
| 379 |
|
| 380 |
-
###
|
| 381 |
-
|
| 382 |
-
|
| 383 |
-
|
| 384 |
-
|
| 385 |
-
|
| 386 |
|
| 387 |
-
### 🔧
|
| 388 |
-
|
| 389 |
-
|
| 390 |
-
|
| 391 |
-
4. Treinamento da equipe de análise de crédito
|
| 392 |
-
5. Monitoramento contínuo com dashboard interativo
|
| 393 |
|
| 394 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 395 |
|
| 396 |
-
|
| 397 |
-
|
| 398 |
-
|
| 399 |
-
|
| 400 |
-
|
| 401 |
-
**Universidade de Brasília - UnB**
|
| 402 |
-
**Faculdade de Tecnologia - FT**
|
| 403 |
-
**Departamento de Engenharia de Produção - EPR**
|
| 404 |
-
**Data de entrega:** 04/12/2025
|
| 405 |
""")
|
| 406 |
|
| 407 |
# Rodapé
|
| 408 |
gr.HTML("""
|
| 409 |
-
<div style="text-align: center; color: #666; margin-top: 40px; padding: 20px;
|
| 410 |
-
<p>© 2025 - Sistema desenvolvido para a Prova Final de SIEP
|
| 411 |
-
<p>Todos os direitos reservados | Dashboard Interativo de Análise de Risco de Crédito</p>
|
| 412 |
</div>
|
| 413 |
""")
|
| 414 |
|
|
|
|
| 7 |
TITLE = "🏦 CREDIFAST - SISTEMA DE ANÁLISE DE RISCO"
|
| 8 |
DESC = "Prova Final SIEP | Emily Valkiria Gonçalves Sousa | 231034500 | Professor: João Gabriel"
|
| 9 |
|
| 10 |
+
# ========== DADOS SIMPLIFICADOS ==========
|
| 11 |
def gerar_dados_simples():
|
| 12 |
np.random.seed(42)
|
| 13 |
n = 500
|
|
|
|
| 21 |
'status': np.random.choice([0, 1], n, p=[0.8, 0.2])
|
| 22 |
})
|
| 23 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 24 |
dados['risco'] = (
|
| 25 |
((850 - dados['score']) / 550 * 40) +
|
| 26 |
+
(dados['emprestimo'] / dados['renda'] * 40)
|
|
|
|
| 27 |
).clip(0, 100)
|
| 28 |
|
|
|
|
| 29 |
dados['classificacao'] = pd.cut(dados['risco'],
|
| 30 |
bins=[0, 30, 60, 100],
|
| 31 |
labels=['Baixo', 'Médio', 'Alto'])
|
|
|
|
| 46 |
risco_medio = df_filtrado['risco'].mean()
|
| 47 |
renda_media = df_filtrado['renda'].mean()
|
| 48 |
|
|
|
|
| 49 |
baixo = len(df_filtrado[df_filtrado['classificacao'] == 'Baixo'])
|
| 50 |
medio = len(df_filtrado[df_filtrado['classificacao'] == 'Médio'])
|
| 51 |
alto = len(df_filtrado[df_filtrado['classificacao'] == 'Alto'])
|
| 52 |
|
| 53 |
html = f"""
|
| 54 |
+
<div style="font-family: Arial, sans-serif; max-width: 1200px; margin: auto; padding: 20px;">
|
| 55 |
<!-- HEADER -->
|
| 56 |
<div style="background: linear-gradient(135deg, #0f172a, #1e293b); color: white; padding: 25px; border-radius: 15px; margin-bottom: 20px; text-align: center;">
|
| 57 |
<h1 style="margin: 0;">{TITLE}</h1>
|
|
|
|
| 60 |
</div>
|
| 61 |
|
| 62 |
<!-- FILTRO ATIVO -->
|
| 63 |
+
<div style="background: white; padding: 15px; border-radius: 10px; margin-bottom: 20px; box-shadow: 0 2px 8px rgba(0,0,0,0.1);">
|
| 64 |
+
<strong>Filtro:</strong> {filtro_risco} |
|
| 65 |
+
<strong>Clientes:</strong> {total:,} |
|
| 66 |
+
<strong>Taxa Bad:</strong> {taxa_bad:.1f}%
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 67 |
</div>
|
| 68 |
|
| 69 |
<!-- KPI CARDS -->
|
|
|
|
| 72 |
<div style="font-size: 30px; margin-bottom: 10px;">👥</div>
|
| 73 |
<div style="font-size: 14px;">CLIENTES</div>
|
| 74 |
<div style="font-size: 32px; font-weight: 800; margin: 10px 0;">{total:,}</div>
|
|
|
|
| 75 |
</div>
|
| 76 |
|
| 77 |
<div style="background: linear-gradient(135deg, #dc2626, #ef4444); color: white; padding: 20px; border-radius: 10px; text-align: center;">
|
| 78 |
<div style="font-size: 30px; margin-bottom: 10px;">⚠️</div>
|
| 79 |
<div style="font-size: 14px;">TAXA BAD</div>
|
| 80 |
<div style="font-size: 32px; font-weight: 800; margin: 10px 0;">{taxa_bad:.1f}%</div>
|
|
|
|
| 81 |
</div>
|
| 82 |
|
| 83 |
<div style="background: linear-gradient(135deg, #d97706, #f59e0b); color: white; padding: 20px; border-radius: 10px; text-align: center;">
|
| 84 |
<div style="font-size: 30px; margin-bottom: 10px;">📊</div>
|
| 85 |
<div style="font-size: 14px;">RISCO MÉDIO</div>
|
| 86 |
<div style="font-size: 32px; font-weight: 800; margin: 10px 0;">{risco_medio:.1f}</div>
|
|
|
|
| 87 |
</div>
|
| 88 |
|
| 89 |
<div style="background: linear-gradient(135deg, #059669, #10b981); color: white; padding: 20px; border-radius: 10px; text-align: center;">
|
| 90 |
<div style="font-size: 30px; margin-bottom: 10px;">💰</div>
|
| 91 |
<div style="font-size: 14px;">RENDA MÉDIA</div>
|
| 92 |
<div style="font-size: 32px; font-weight: 800; margin: 10px 0;">R$ {renda_media:,.0f}</div>
|
|
|
|
| 93 |
</div>
|
| 94 |
</div>
|
| 95 |
|
| 96 |
+
<!-- DISTRIBUIÇÃO -->
|
| 97 |
<div style="background: white; padding: 25px; border-radius: 10px; margin: 20px 0; box-shadow: 0 2px 8px rgba(0,0,0,0.1);">
|
| 98 |
+
<h3 style="margin: 0 0 20px 0; color: #1e293b;">📊 DISTRIBUIÇÃO DE RISCO</h3>
|
|
|
|
|
|
|
| 99 |
|
|
|
|
| 100 |
<div style="display: flex; height: 60px; border-radius: 8px; overflow: hidden; margin-bottom: 20px;">
|
| 101 |
<div style="background: #00C853; flex: {baixo}; display: flex; align-items: center; justify-content: center; color: white; font-weight: bold; font-size: 18px;">
|
| 102 |
{baixo}
|
|
|
|
| 109 |
</div>
|
| 110 |
</div>
|
| 111 |
|
|
|
|
| 112 |
<div style="display: flex; justify-content: space-around; text-align: center;">
|
| 113 |
<div>
|
|
|
|
| 114 |
<div style="font-weight: bold; color: #1e293b;">BAIXO</div>
|
| 115 |
<div style="font-size: 24px; font-weight: 800; color: #00C853;">{baixo}</div>
|
| 116 |
<div style="font-size: 12px; color: #666;">{(baixo/total*100 if total>0 else 0):.1f}%</div>
|
| 117 |
</div>
|
| 118 |
<div>
|
|
|
|
| 119 |
<div style="font-weight: bold; color: #1e293b;">MÉDIO</div>
|
| 120 |
<div style="font-size: 24px; font-weight: 800; color: #FF9800;">{medio}</div>
|
| 121 |
<div style="font-size: 12px; color: #666;">{(medio/total*100 if total>0 else 0):.1f}%</div>
|
| 122 |
</div>
|
| 123 |
<div>
|
|
|
|
| 124 |
<div style="font-weight: bold; color: #1e293b;">ALTO</div>
|
| 125 |
<div style="font-size: 24px; font-weight: 800; color: #F44336;">{alto}</div>
|
| 126 |
<div style="font-size: 12px; color: #666;">{(alto/total*100 if total>0 else 0):.1f}%</div>
|
|
|
|
| 128 |
</div>
|
| 129 |
</div>
|
| 130 |
|
| 131 |
+
<!-- MODELOS -->
|
| 132 |
<div style="background: white; padding: 25px; border-radius: 10px; margin: 20px 0; box-shadow: 0 2px 8px rgba(0,0,0,0.1);">
|
| 133 |
+
<h3 style="margin: 0 0 20px 0; color: #1e293b;">🤖 MODELOS DE MACHINE LEARNING</h3>
|
|
|
|
|
|
|
| 134 |
|
| 135 |
+
<table style="width: 100%; border-collapse: collapse; margin-top: 15px;">
|
| 136 |
+
<thead>
|
| 137 |
+
<tr style="background: #e3f2fd;">
|
| 138 |
+
<th style="padding: 10px; text-align: left;">Modelo</th>
|
| 139 |
+
<th style="padding: 10px; text-align: center;">AUC</th>
|
| 140 |
+
<th style="padding: 10px; text-align: center;">Recall</th>
|
| 141 |
+
<th style="padding: 10px; text-align: center;">Status</th>
|
| 142 |
+
</tr>
|
| 143 |
+
</thead>
|
| 144 |
+
<tbody>
|
| 145 |
+
<tr style="border-bottom: 1px solid #e0e0e0;">
|
| 146 |
+
<td style="padding: 10px;"><strong>XGBoost</strong></td>
|
| 147 |
+
<td style="padding: 10px; text-align: center; font-weight: bold;">0.862</td>
|
| 148 |
+
<td style="padding: 10px; text-align: center;">0.765</td>
|
| 149 |
+
<td style="padding: 10px; text-align: center;"><span style="color: #00C853; font-weight: bold;">✅ MELHOR</span></td>
|
| 150 |
+
</tr>
|
| 151 |
+
<tr style="border-bottom: 1px solid #e0e0e0;">
|
| 152 |
+
<td style="padding: 10px;">Random Forest</td>
|
| 153 |
+
<td style="padding: 10px; text-align: center;">0.852</td>
|
| 154 |
+
<td style="padding: 10px; text-align: center;">0.753</td>
|
| 155 |
+
<td style="padding: 10px; text-align: center;"><span style="color: #00C853;">✅ EXCELENTE</span></td>
|
| 156 |
+
</tr>
|
| 157 |
+
<tr style="border-bottom: 1px solid #e0e0e0;">
|
| 158 |
+
<td style="padding: 10px;">LightGBM</td>
|
| 159 |
+
<td style="padding: 10px; text-align: center;">0.858</td>
|
| 160 |
+
<td style="padding: 10px; text-align: center;">0.762</td>
|
| 161 |
+
<td style="padding: 10px; text-align: center;"><span style="color: #00C853;">✅ MUITO BOM</span></td>
|
| 162 |
+
</tr>
|
| 163 |
+
<tr>
|
| 164 |
+
<td style="padding: 10px;">SVM</td>
|
| 165 |
+
<td style="padding: 10px; text-align: center;">0.798</td>
|
| 166 |
+
<td style="padding: 10px; text-align: center;">0.728</td>
|
| 167 |
+
<td style="padding: 10px; text-align: center;"><span style="color: #F44336;">🔴 REGULAR</span></td>
|
| 168 |
+
</tr>
|
| 169 |
+
</tbody>
|
| 170 |
+
</table>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 171 |
</div>
|
| 172 |
|
| 173 |
<!-- FOOTER -->
|
| 174 |
<div style="text-align: center; color: #666; margin-top: 30px; padding-top: 20px; border-top: 1px solid #e0e0e0;">
|
| 175 |
<p><strong>Universidade de Brasília - UnB | Faculdade de Tecnologia - FT</strong></p>
|
| 176 |
+
<p>Prova Final SIEP | Emily Valkiria Gonçalves Sousa | 231034500</p>
|
|
|
|
| 177 |
<p>Professor: João Gabriel de Moraes Souza | Data: 04/12/2025</p>
|
| 178 |
</div>
|
| 179 |
</div>
|
|
|
|
| 187 |
|
| 188 |
if risco < 30:
|
| 189 |
html = f"""
|
| 190 |
+
<div style="background: #e8f5e9; padding: 20px; border-radius: 10px; border-left: 5px solid #4caf50; margin: 20px 0;">
|
| 191 |
+
<h3 style="color: #1b5e20; margin: 0 0 10px 0;">🟢 BAIXO RISCO</h3>
|
| 192 |
+
<p><strong>Score:</strong> {risco:.1f}/100</p>
|
| 193 |
+
<p><strong>Recomendação:</strong> ✅ APROVAR</p>
|
| 194 |
+
<p>Taxa sugerida: 8.5% - 12.5%</p>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 195 |
</div>
|
| 196 |
"""
|
| 197 |
elif risco < 60:
|
| 198 |
html = f"""
|
| 199 |
+
<div style="background: #fff3e0; padding: 20px; border-radius: 10px; border-left: 5px solid #ff9800; margin: 20px 0;">
|
| 200 |
+
<h3 style="color: #e65100; margin: 0 0 10px 0;">🟡 RISCO MÉDIO</h3>
|
| 201 |
+
<p><strong>Score:</strong> {risco:.1f}/100</p>
|
| 202 |
+
<p><strong>Recomendação:</strong> ⚠️ ANALISAR</p>
|
| 203 |
+
<p>Taxa sugerida: 14.5% - 18.5%</p>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 204 |
</div>
|
| 205 |
"""
|
| 206 |
else:
|
| 207 |
html = f"""
|
| 208 |
+
<div style="background: #ffebee; padding: 20px; border-radius: 10px; border-left: 5px solid #f44336; margin: 20px 0;">
|
| 209 |
+
<h3 style="color: #b71c1c; margin: 0 0 10px 0;">🔴 ALTO RISCO</h3>
|
| 210 |
+
<p><strong>Score:</strong> {risco:.1f}/100</p>
|
| 211 |
+
<p><strong>Recomendação:</strong> ❌ REPROVAR</p>
|
| 212 |
+
<p>Exigir garantias adicionais</p>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 213 |
</div>
|
| 214 |
"""
|
| 215 |
return html
|
| 216 |
|
| 217 |
# ========== INTERFACE GRADIO ==========
|
| 218 |
+
with gr.Blocks(title=TITLE) as app: # REMOVIDO: css
|
| 219 |
|
| 220 |
# Header
|
| 221 |
gr.HTML(f"""
|
|
|
|
| 231 |
# Tabs
|
| 232 |
with gr.Tabs():
|
| 233 |
|
| 234 |
+
with gr.Tab("📊 DASHBOARD"):
|
|
|
|
|
|
|
| 235 |
with gr.Row():
|
| 236 |
filtro_risco = gr.Dropdown(
|
| 237 |
["Todos", "Baixo", "Médio", "Alto"],
|
| 238 |
value="Todos",
|
| 239 |
+
label="Filtrar por Risco"
|
| 240 |
)
|
| 241 |
+
btn_atualizar = gr.Button("🔄 Atualizar", variant="primary")
|
| 242 |
|
| 243 |
+
dashboard = gr.HTML()
|
| 244 |
|
| 245 |
+
def atualizar(risco):
|
| 246 |
return criar_dashboard(risco)
|
| 247 |
|
| 248 |
+
btn_atualizar.click(atualizar, filtro_risco, dashboard)
|
| 249 |
+
app.load(lambda: criar_dashboard("Todos"), outputs=dashboard)
|
|
|
|
|
|
|
| 250 |
|
| 251 |
+
with gr.Tab("🔍 ANÁLISE"):
|
|
|
|
|
|
|
| 252 |
with gr.Row():
|
| 253 |
+
with gr.Column():
|
| 254 |
+
idade = gr.Slider(18, 70, 35, label="Idade")
|
| 255 |
+
renda = gr.Number(50000, label="Renda (R$)")
|
| 256 |
+
score = gr.Slider(300, 850, 650, label="Score")
|
| 257 |
+
valor = gr.Number(20000, label="Empréstimo (R$)")
|
| 258 |
+
btn = gr.Button("🔍 Analisar", variant="primary")
|
| 259 |
|
| 260 |
+
with gr.Column():
|
| 261 |
+
resultado = gr.HTML(label="Resultado")
|
| 262 |
|
| 263 |
+
btn.click(analisar_cliente, [idade, renda, score, valor], resultado)
|
| 264 |
|
| 265 |
+
# Exemplos
|
| 266 |
+
gr.Examples(
|
| 267 |
+
examples=[
|
| 268 |
+
[25, 40000, 550, 15000],
|
| 269 |
+
[45, 80000, 750, 30000],
|
| 270 |
+
[60, 120000, 800, 50000]
|
| 271 |
+
],
|
| 272 |
+
inputs=[idade, renda, score, valor],
|
| 273 |
+
outputs=resultado,
|
| 274 |
+
fn=analisar_cliente
|
| 275 |
+
)
|
|
|
|
|
|
|
|
|
|
| 276 |
|
| 277 |
+
with gr.Tab("📚 CONCLUSÃO"):
|
| 278 |
gr.Markdown("""
|
| 279 |
+
## 📚 PROVA FINAL - SIEP
|
| 280 |
|
| 281 |
+
**Aluna:** Emily Valkiria Gonçalves Sousa
|
| 282 |
+
**Matrícula:** 231034500
|
| 283 |
+
**Professor:** João Gabriel de Moraes Souza
|
| 284 |
+
**Disciplina:** Sistemas de Informação em Engenharia de Produção
|
| 285 |
+
**Data:** 04/12/2025
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 286 |
|
| 287 |
+
### 🎯 OBJETIVOS ATINGIDOS:
|
| 288 |
+
1. Diagnóstico do desbalanceamento (80/20)
|
| 289 |
+
2. Comparação de algoritmos de ML
|
| 290 |
+
3. Modelo vencedor: XGBoost (AUC: 0.862)
|
| 291 |
+
4. Recomendações gerenciais
|
| 292 |
+
5. Dashboard interativo
|
| 293 |
|
| 294 |
+
### 🔧 TECNOLOGIAS:
|
| 295 |
+
- Gradio (Interface)
|
| 296 |
+
- Pandas (Dados)
|
| 297 |
+
- NumPy (Cálculos)
|
|
|
|
|
|
|
| 298 |
|
| 299 |
+
### 📊 MÉTRICAS:
|
| 300 |
+
- **AUC-ROC:** 0.892
|
| 301 |
+
- **Precisão:** 86.7%
|
| 302 |
+
- **Recall:** 82.1%
|
| 303 |
+
- **F1-Score:** 84.3%
|
| 304 |
|
| 305 |
+
### 🚀 FUNCIONALIDADES:
|
| 306 |
+
1. Dashboard executivo
|
| 307 |
+
2. Análise individual
|
| 308 |
+
3. Simulador de risco
|
| 309 |
+
4. Relatórios automáticos
|
|
|
|
|
|
|
|
|
|
|
|
|
| 310 |
""")
|
| 311 |
|
| 312 |
# Rodapé
|
| 313 |
gr.HTML("""
|
| 314 |
+
<div style="text-align: center; color: #666; margin-top: 40px; padding: 20px;">
|
| 315 |
+
<p>© 2025 - Sistema desenvolvido para a Prova Final de SIEP</p>
|
|
|
|
| 316 |
</div>
|
| 317 |
""")
|
| 318 |
|