jcmachicao
commited on
Commit
•
0d7c039
1
Parent(s):
f441ea7
Upload app_streamlit.py
Browse files- app_streamlit.py +73 -0
app_streamlit.py
ADDED
@@ -0,0 +1,73 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# Actualizado por: José Carlos Machicao, Fecha de actualización: 2024_07_08, Lima
|
2 |
+
# Esta vinculado a los PKL de https://sites.google.com/continental.edu.pe/edusights/inicio
|
3 |
+
|
4 |
+
# Importacion de librerias
|
5 |
+
import torch
|
6 |
+
import torch.nn as nn
|
7 |
+
import pandas as pd
|
8 |
+
import numpy as np
|
9 |
+
from sklearn.preprocessing import StandardScaler, MinMaxScaler
|
10 |
+
from sklearn.model_selection import train_test_split
|
11 |
+
from torch.utils.data import DataLoader, TensorDataset
|
12 |
+
import plotly.express as px
|
13 |
+
import streamlit as st
|
14 |
+
from es_class_nn import SimplePlusNN2
|
15 |
+
version_name = 'CON_31'
|
16 |
+
|
17 |
+
c1, c2 = st.columns([6,6])
|
18 |
+
with c2:
|
19 |
+
st.image('logo_vidad.png', width=300, caption='https://www.continental.edu.pe/')
|
20 |
+
|
21 |
+
st.title("Predicción de Abandono o Permanencia")
|
22 |
+
st.write("Cargue el archivo PKL para visualizar el análisis de su contenido.")
|
23 |
+
|
24 |
+
uploaded_file = st.file_uploader("Cargar archivo: ", type='xlsx')
|
25 |
+
|
26 |
+
cat_sel = pd.read_excel('df_cat_prior.xlsx')
|
27 |
+
df_categ = pd.read_excel('lista_categorias.xlsx')
|
28 |
+
df_muestra = pd.read_excel('df_muestra_carga.xlsx')
|
29 |
+
|
30 |
+
if uploaded_file is not None:
|
31 |
+
|
32 |
+
# Lectura del archivo de predicción
|
33 |
+
df_test = pd.read_excel(uploaded_file)
|
34 |
+
verif = df_test.columns == df_muestra.columns
|
35 |
+
st.write(verif.sum())
|
36 |
+
df_scaled = pd.concat([df_muestra, df_test], axis=0, ignore_index=True)
|
37 |
+
df_scaled = df_scaled.fillna(0)
|
38 |
+
df = df_scaled.tail(len(df_test)).reset_index(drop=True)
|
39 |
+
st.write(df)
|
40 |
+
X = df.values
|
41 |
+
X_test_tensor = torch.tensor(X.astype(np.float32), dtype=torch.float32)
|
42 |
+
|
43 |
+
# Carga de Modelo Entrenado
|
44 |
+
input_size = X_test_tensor.shape[1]
|
45 |
+
num_classes = 2
|
46 |
+
model = SimplePlusNN2(input_size, num_classes)
|
47 |
+
data_path = ''
|
48 |
+
dict_name = f'edusights_20240702_state_dict_{version_name}.pth'
|
49 |
+
model.load_state_dict(torch.load(data_path+dict_name))
|
50 |
+
model.eval()
|
51 |
+
|
52 |
+
# Predicciones
|
53 |
+
inputs = X_test_tensor
|
54 |
+
outputs = model(inputs)
|
55 |
+
outputs_show = outputs.detach().numpy().flatten()
|
56 |
+
outputs_show[outputs_show > 0.60] = 1.0
|
57 |
+
outputs_show[outputs_show < 0.40] = 0.0
|
58 |
+
filtered_arr = outputs_show[(outputs_show == 0.0) | (outputs_show == 1.0)]
|
59 |
+
df['Pred'] = filtered_arr
|
60 |
+
st.write(df['Pred'])
|
61 |
+
|
62 |
+
csv_out = df.to_csv(encoding='iso-8859-1')
|
63 |
+
|
64 |
+
st.download_button(
|
65 |
+
label="Descargar CSV",
|
66 |
+
data=csv_out,
|
67 |
+
file_name='predicciones_carga.csv',
|
68 |
+
mime='text/csv'
|
69 |
+
)
|
70 |
+
|
71 |
+
c3, c4 = st.columns([6,6])
|
72 |
+
with c3:
|
73 |
+
st.image('gdmklogo.png', width=100, caption='Powered by GestioDinámica 2024')
|