Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -5,7 +5,7 @@ import plotly.graph_objects as go
|
|
5 |
import gradio as gr
|
6 |
from gradio.components import Plot
|
7 |
|
8 |
-
#
|
9 |
|
10 |
cities_data = {
|
11 |
'Abancay': {
|
@@ -1151,7 +1151,7 @@ cities_data = {
|
|
1151 |
}
|
1152 |
|
1153 |
|
1154 |
-
#
|
1155 |
|
1156 |
COLORES = {
|
1157 |
'Total': '#2C3E50',
|
@@ -1195,10 +1195,13 @@ def crear_grafico_lineas(df, titulo, eje_y, formato=None):
|
|
1195 |
y=df[columna],
|
1196 |
name=columna,
|
1197 |
mode='lines+markers',
|
1198 |
-
line=dict(
|
|
|
|
|
|
|
1199 |
marker=dict(size=8),
|
1200 |
hovertemplate=f'<b>{columna}</b>: %{{y:{formato or ".2f"}}}<extra></extra>'
|
1201 |
-
))
|
1202 |
|
1203 |
fig.update_layout(
|
1204 |
title=dict(text=titulo, x=0.5, font=dict(size=20)),
|
@@ -1251,17 +1254,8 @@ def crear_radar_plot(dfs):
|
|
1251 |
|
1252 |
fig.update_layout(
|
1253 |
polar=dict(
|
1254 |
-
radialaxis=dict(
|
1255 |
-
|
1256 |
-
range=[0, 100],
|
1257 |
-
tickfont=dict(size=12)
|
1258 |
-
),
|
1259 |
-
angularaxis=dict(
|
1260 |
-
rotation=90,
|
1261 |
-
direction='clockwise',
|
1262 |
-
tickfont=dict(size=14)
|
1263 |
-
)
|
1264 |
-
),
|
1265 |
title=dict(text='Radar de Indicadores Laborales', x=0.5, font=dict(size=20)),
|
1266 |
showlegend=False,
|
1267 |
height=500
|
@@ -1305,11 +1299,9 @@ def analisis_comparativo_desempleo():
|
|
1305 |
|
1306 |
def generar_analisis_global():
|
1307 |
figs = []
|
1308 |
-
|
1309 |
-
# Gr谩fico comparativo de desempleo
|
1310 |
figs.append(analisis_comparativo_desempleo())
|
1311 |
|
1312 |
-
# Gr谩fico de
|
1313 |
datos_ingresos = []
|
1314 |
for ciudad, data in cities_data.items():
|
1315 |
nombre = normalizar_nombres_ciudades(ciudad)
|
@@ -1321,18 +1313,14 @@ def generar_analisis_global():
|
|
1321 |
|
1322 |
if datos_ingresos:
|
1323 |
df_ingresos = pd.concat(datos_ingresos)
|
1324 |
-
fig_ingresos = px.line(df_ingresos,
|
1325 |
-
|
1326 |
-
y='Total',
|
1327 |
-
color='Ciudad',
|
1328 |
-
title='Evoluci贸n de Ingresos por Ciudad',
|
1329 |
-
markers=True)
|
1330 |
fig_ingresos.update_layout(height=600)
|
1331 |
figs.append(fig_ingresos)
|
1332 |
else:
|
1333 |
figs.append(go.Figure())
|
1334 |
|
1335 |
-
# Gr谩fico de brecha
|
1336 |
datos_brecha = []
|
1337 |
for ciudad, data in cities_data.items():
|
1338 |
nombre = normalizar_nombres_ciudades(ciudad)
|
@@ -1345,12 +1333,8 @@ def generar_analisis_global():
|
|
1345 |
|
1346 |
if datos_brecha:
|
1347 |
df_brecha = pd.concat(datos_brecha)
|
1348 |
-
fig_brecha = px.bar(df_brecha,
|
1349 |
-
|
1350 |
-
y='Brecha',
|
1351 |
-
color='Ciudad',
|
1352 |
-
barmode='group',
|
1353 |
-
title='Evoluci贸n de Brecha Salarial por Ciudad',
|
1354 |
text_auto='.1f%')
|
1355 |
fig_brecha.update_layout(height=600)
|
1356 |
figs.append(fig_brecha)
|
@@ -1359,9 +1343,7 @@ def generar_analisis_global():
|
|
1359 |
|
1360 |
return figs
|
1361 |
|
1362 |
-
with gr.Blocks(theme=gr.themes.Soft(primary_hue="blue"),
|
1363 |
-
css=".gradio-container {background-color: white}") as app:
|
1364 |
-
|
1365 |
gr.Markdown("# 馃搳 Dashboard Anal铆tico del Mercado Laboral")
|
1366 |
|
1367 |
with gr.Row():
|
@@ -1389,37 +1371,40 @@ with gr.Blocks(theme=gr.themes.Soft(primary_hue="blue"),
|
|
1389 |
with gr.Row():
|
1390 |
global_ingresos = Plot(label="Comparativa de Ingresos")
|
1391 |
global_brecha = Plot(label="Evoluci贸n Brecha Salarial")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1392 |
|
1393 |
-
|
1394 |
-
|
1395 |
-
|
1396 |
-
|
1397 |
-
|
1398 |
-
|
1399 |
-
|
1400 |
-
|
1401 |
-
|
1402 |
-
|
1403 |
-
|
1404 |
-
|
1405 |
-
|
1406 |
-
|
1407 |
-
|
1408 |
-
}
|
1409 |
-
|
1410 |
-
return [
|
1411 |
-
crear_grafico_lineas(dfs['desempleo'], "Tasa de Desempleo", "%", ".1f"),
|
1412 |
-
crear_grafico_lineas(dfs['ingresos'], "Ingresos Promedio", "Soles", ".0f"),
|
1413 |
-
crear_grafico_lineas(dfs['informal'], "Tasa de Informalidad", "%", ".1f"),
|
1414 |
-
crear_grafico_lineas(dfs['actividad'], "Tasa de Actividad", "%", ".1f"),
|
1415 |
-
crear_radar_plot(dfs),
|
1416 |
-
crear_grafico_lineas(dfs['ingresos'].assign(
|
1417 |
-
Brecha=lambda x: (x['Hombres'] - x['Mujeres']) / x['Hombres'].replace(0, np.nan) * 100
|
1418 |
-
), "Brecha Salarial", "%", ".1f")
|
1419 |
-
]
|
1420 |
|
1421 |
-
|
1422 |
-
|
1423 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1424 |
|
1425 |
app.launch(debug=True)
|
|
|
5 |
import gradio as gr
|
6 |
from gradio.components import Plot
|
7 |
|
8 |
+
#DATA
|
9 |
|
10 |
cities_data = {
|
11 |
'Abancay': {
|
|
|
1151 |
}
|
1152 |
|
1153 |
|
1154 |
+
#DATA
|
1155 |
|
1156 |
COLORES = {
|
1157 |
'Total': '#2C3E50',
|
|
|
1195 |
y=df[columna],
|
1196 |
name=columna,
|
1197 |
mode='lines+markers',
|
1198 |
+
line=dict(
|
1199 |
+
color=COLORES.get(columna, '#000000'),
|
1200 |
+
width=3
|
1201 |
+
),
|
1202 |
marker=dict(size=8),
|
1203 |
hovertemplate=f'<b>{columna}</b>: %{{y:{formato or ".2f"}}}<extra></extra>'
|
1204 |
+
))
|
1205 |
|
1206 |
fig.update_layout(
|
1207 |
title=dict(text=titulo, x=0.5, font=dict(size=20)),
|
|
|
1254 |
|
1255 |
fig.update_layout(
|
1256 |
polar=dict(
|
1257 |
+
radialaxis=dict(visible=True, range=[0, 100], tickfont=dict(size=12)),
|
1258 |
+
angularaxis=dict(rotation=90, direction='clockwise', tickfont=dict(size=14)),
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1259 |
title=dict(text='Radar de Indicadores Laborales', x=0.5, font=dict(size=20)),
|
1260 |
showlegend=False,
|
1261 |
height=500
|
|
|
1299 |
|
1300 |
def generar_analisis_global():
|
1301 |
figs = []
|
|
|
|
|
1302 |
figs.append(analisis_comparativo_desempleo())
|
1303 |
|
1304 |
+
# Gr谩fico de ingresos
|
1305 |
datos_ingresos = []
|
1306 |
for ciudad, data in cities_data.items():
|
1307 |
nombre = normalizar_nombres_ciudades(ciudad)
|
|
|
1313 |
|
1314 |
if datos_ingresos:
|
1315 |
df_ingresos = pd.concat(datos_ingresos)
|
1316 |
+
fig_ingresos = px.line(df_ingresos, x='Periodo', y='Total', color='Ciudad',
|
1317 |
+
title='Evoluci贸n de Ingresos por Ciudad', markers=True)
|
|
|
|
|
|
|
|
|
1318 |
fig_ingresos.update_layout(height=600)
|
1319 |
figs.append(fig_ingresos)
|
1320 |
else:
|
1321 |
figs.append(go.Figure())
|
1322 |
|
1323 |
+
# Gr谩fico de brecha
|
1324 |
datos_brecha = []
|
1325 |
for ciudad, data in cities_data.items():
|
1326 |
nombre = normalizar_nombres_ciudades(ciudad)
|
|
|
1333 |
|
1334 |
if datos_brecha:
|
1335 |
df_brecha = pd.concat(datos_brecha)
|
1336 |
+
fig_brecha = px.bar(df_brecha, x='Periodo', y='Brecha', color='Ciudad',
|
1337 |
+
barmode='group', title='Evoluci贸n de Brecha Salarial por Ciudad',
|
|
|
|
|
|
|
|
|
1338 |
text_auto='.1f%')
|
1339 |
fig_brecha.update_layout(height=600)
|
1340 |
figs.append(fig_brecha)
|
|
|
1343 |
|
1344 |
return figs
|
1345 |
|
1346 |
+
with gr.Blocks(theme=gr.themes.Soft(primary_hue="blue"), css=".gradio-container {background-color: white}") as app:
|
|
|
|
|
1347 |
gr.Markdown("# 馃搳 Dashboard Anal铆tico del Mercado Laboral")
|
1348 |
|
1349 |
with gr.Row():
|
|
|
1371 |
with gr.Row():
|
1372 |
global_ingresos = Plot(label="Comparativa de Ingresos")
|
1373 |
global_brecha = Plot(label="Evoluci贸n Brecha Salarial")
|
1374 |
+
global_btn = gr.Button("Actualizar An谩lisis Global", variant="primary")
|
1375 |
+
|
1376 |
+
# Eventos
|
1377 |
+
ciudad.change(
|
1378 |
+
fn=actualizar_graficos,
|
1379 |
+
inputs=ciudad,
|
1380 |
+
outputs=[desempleo_plot, ingresos_plot, informalidad_plot, actividad_plot, radar_plot, brecha_plot]
|
1381 |
+
)
|
1382 |
|
1383 |
+
global_btn.click(
|
1384 |
+
fn=generar_analisis_global,
|
1385 |
+
inputs=[],
|
1386 |
+
outputs=[global_desempleo, global_ingresos, global_brecha]
|
1387 |
+
)
|
1388 |
+
|
1389 |
+
def actualizar_graficos(ciudad):
|
1390 |
+
data = cities_data[ciudad]
|
1391 |
+
|
1392 |
+
dfs = {
|
1393 |
+
'desempleo': procesar_dataframe(data['desempleo_trimestral'], ["Trimestre", "Total", "Hombres", "Mujeres"]),
|
1394 |
+
'ingresos': procesar_dataframe(data['ingresos_periodo'], ["Periodo", "Total", "Hombres", "Mujeres"]),
|
1395 |
+
'informal': procesar_dataframe(data['informal_periodo'], ["Periodo", "Total", "Hombres", "Mujeres"]),
|
1396 |
+
'actividad': procesar_dataframe(data['actividad_trimestral'], ["Trimestre", "Total", "Hombres", "Mujeres"])
|
1397 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1398 |
|
1399 |
+
return [
|
1400 |
+
crear_grafico_lineas(dfs['desempleo'], "Tasa de Desempleo", "%", ".1f"),
|
1401 |
+
crear_grafico_lineas(dfs['ingresos'], "Ingresos Promedio", "Soles", ".0f"),
|
1402 |
+
crear_grafico_lineas(dfs['informal'], "Tasa de Informalidad", "%", ".1f"),
|
1403 |
+
crear_grafico_lineas(dfs['actividad'], "Tasa de Actividad", "%", ".1f"),
|
1404 |
+
crear_radar_plot(dfs),
|
1405 |
+
crear_grafico_lineas(dfs['ingresos'].assign(
|
1406 |
+
Brecha=lambda x: (x['Hombres'] - x['Mujeres']) / x['Hombres'].replace(0, np.nan) * 100
|
1407 |
+
), "Brecha Salarial", "%", ".1f")
|
1408 |
+
]
|
1409 |
|
1410 |
app.launch(debug=True)
|