Spaces:
No application file
No application file
Upload 3 files
Browse files- app (1).py +111 -0
- modelo_xgboost.json +0 -0
- requirements (1).txt +4 -0
app (1).py
ADDED
@@ -0,0 +1,111 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from pathlib import Path
|
3 |
+
import os
|
4 |
+
import pandas as pd
|
5 |
+
import xgboost
|
6 |
+
|
7 |
+
# Comentario
|
8 |
+
print("Comentario.")
|
9 |
+
|
10 |
+
input_1 = gr.Slider(minimum=0, maximum=80,
|
11 |
+
value=22,
|
12 |
+
label="Edad_del_comprador", info="Colocar una edad")
|
13 |
+
|
14 |
+
input_2 = gr.Radio(['Youth (<25)', 'Adults (35-64)', 'Young Adults (25-34)', 'Seniors (64+)'],
|
15 |
+
value="Youth (<25)",
|
16 |
+
label="Grupo_de_edad", info="Seleccionar una opci贸n")
|
17 |
+
|
18 |
+
input_3 = gr.Radio(['M', 'F'],
|
19 |
+
value="M",
|
20 |
+
label="Genero_del_cliente", info="Seleccionar una opci贸n")
|
21 |
+
|
22 |
+
input_4 = gr.Radio(['Canada', 'Australia', 'United States', 'Germany', 'France', 'United Kingdom'],
|
23 |
+
value="United States",
|
24 |
+
label="Pais", info="Seleccionar una opci贸n")
|
25 |
+
|
26 |
+
input_5 = gr.Radio(['British Columbia', 'New South Wales', 'Victoria', 'Oregon', 'California',
|
27 |
+
'Saarland', 'Seine Saint Denis', 'Moselle', 'Queensland', 'England', 'Nord',
|
28 |
+
'Washington', 'Hessen', 'Nordrhein-Westfalen', 'Hamburg', 'Loir et Cher',
|
29 |
+
'Kentucky', 'Seine (Paris)', 'South Australia', 'Loiret', 'Alberta', 'Bayern',
|
30 |
+
'Hauts de Seine', 'Yveline', 'Essonne', "Val d'Oise", 'Tasmania',
|
31 |
+
'Seine et Marne', 'Val de Marne', 'Pas de Calais', 'Charente-Maritime',
|
32 |
+
'Garonne (Haute)', 'Brandenburg', 'Texas', 'New York', 'Florida', 'Somme',
|
33 |
+
'Illinois', 'South Carolina', 'North Carolina', 'Georgia', 'Virginia', 'Ohio',
|
34 |
+
'Ontario', 'Wyoming', 'Missouri', 'Montana', 'Utah', 'Minnesota', 'Mississippi',
|
35 |
+
'Massachusetts', 'Arizona', 'Alabama'],
|
36 |
+
value="California",
|
37 |
+
label="Estado", info="Seleccionar una opci贸n")
|
38 |
+
|
39 |
+
input_6 = gr.Radio(['Accessories', 'Clothing', 'Bikes'],
|
40 |
+
value="Bikes",
|
41 |
+
label="Categoria_del_producto", info="Seleccionar una opci贸n")
|
42 |
+
|
43 |
+
input_7 = gr.Radio(['Bike Racks', 'Bike Stands', 'Bottles and Cages', 'Caps', 'Cleaners',
|
44 |
+
'Fenders', 'Gloves', 'Helmets', 'Hydration Packs', 'Jerseys', 'Mountain Bikes',
|
45 |
+
'Road Bikes', 'Shorts', 'Socks', 'Tires and Tubes', 'Touring Bikes', 'Vests'],
|
46 |
+
value='Bike Racks',
|
47 |
+
label="Subcategor铆a_del_producto", info="Seleccionar una opci贸n")
|
48 |
+
|
49 |
+
input_8 = gr.Slider(minimum=1, maximum=40,
|
50 |
+
value=1,
|
51 |
+
label="Cantidad_de_pedidos_realizados", info="Colocar una opci贸n")
|
52 |
+
|
53 |
+
input_9 = gr.Slider(minimum=1, maximum=40,
|
54 |
+
value=1,
|
55 |
+
label="Precio_unitario", info="Colocar una opci贸n")
|
56 |
+
|
57 |
+
output_1 = gr.Textbox(label="Ingresos")
|
58 |
+
|
59 |
+
|
60 |
+
def predecir_ingreso(input_1, input_2, input_3, input_4, input_5,
|
61 |
+
input_6, input_7, input_8, input_9):
|
62 |
+
|
63 |
+
valores = {
|
64 |
+
'Edad_del_comprador':input_1,
|
65 |
+
'Grupo_de_edad':input_2,
|
66 |
+
'Genero_del_cliente':input_3,
|
67 |
+
'Pais':input_4,
|
68 |
+
'Estado':input_5,
|
69 |
+
'Categoria_del_producto':input_6,
|
70 |
+
'Subcategor铆a_del_producto':input_7,
|
71 |
+
'Cantidad_de_pedidos_realizados':input_8,
|
72 |
+
'Precio_unitario':input_9
|
73 |
+
}
|
74 |
+
|
75 |
+
valores_df = pd.DataFrame()
|
76 |
+
valores_df = pd.concat([valores_df, pd.DataFrame([valores])], ignore_index=True)
|
77 |
+
|
78 |
+
valores_df["Grupo_de_edad"] = valores_df["Grupo_de_edad"].astype("category")
|
79 |
+
valores_df["Genero_del_cliente"] = valores_df["Genero_del_cliente"].astype("category")
|
80 |
+
valores_df["Pais"] = valores_df["Pais"].astype("category")
|
81 |
+
valores_df["Estado"] = valores_df["Estado"].astype("category")
|
82 |
+
valores_df["Categoria_del_producto"] = valores_df["Categoria_del_producto"].astype("category")
|
83 |
+
valores_df["Subcategor铆a_del_producto"] = valores_df["Subcategor铆a_del_producto"].astype("category")
|
84 |
+
|
85 |
+
# Cargar el modelo desde el archivo
|
86 |
+
model_file = f"{os.getcwd()}/modelo_xgboost.json"
|
87 |
+
print(model_file)
|
88 |
+
modelo_cargado = xgboost.Booster(model_file=model_file)
|
89 |
+
|
90 |
+
# Crear una matriz DMatrix para los nuevos datos
|
91 |
+
dmatrix_valores = xgboost.DMatrix(data=valores_df, enable_categorical=True)
|
92 |
+
|
93 |
+
# Realizar predicciones
|
94 |
+
predicciones = modelo_cargado.predict(dmatrix_valores)[0]
|
95 |
+
|
96 |
+
# Las predicciones se encuentran en el array 'predicciones'
|
97 |
+
print(predicciones)
|
98 |
+
return predicciones
|
99 |
+
|
100 |
+
|
101 |
+
# Interfaz Gradio
|
102 |
+
|
103 |
+
demo = gr.Interface(
|
104 |
+
fn=predecir_ingreso,
|
105 |
+
inputs=[input_1, input_2, input_3, input_4, input_5,
|
106 |
+
input_6, input_7, input_8, input_9],
|
107 |
+
outputs=output_1,
|
108 |
+
title="Practica 1 de Machine Learning",
|
109 |
+
)
|
110 |
+
|
111 |
+
demo.launch(debug=True)
|
modelo_xgboost.json
ADDED
The diff for this file is too large to render.
See raw diff
|
|
requirements (1).txt
ADDED
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
1 |
+
gradio
|
2 |
+
pandas
|
3 |
+
numpy
|
4 |
+
xgboost
|