Spaces:
Sleeping
Sleeping
Juan Acevedo commited on
Commit ·
7202d3f
1
Parent(s): 829fa3b
add
Browse files- app.py +63 -0
- final_pipe_less.pkl +3 -0
- requirements.txt +4 -0
app.py
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import joblib
|
| 3 |
+
import numpy as np
|
| 4 |
+
|
| 5 |
+
# Cargar el modelo entrenado
|
| 6 |
+
model = joblib.load('compra_o_no/shopper/final_pipe_less.pkl')
|
| 7 |
+
|
| 8 |
+
# Descripción de las variables de entrada
|
| 9 |
+
feature_descriptions = {
|
| 10 |
+
"PageValues": "Valor económico estimado de la visita (mayor valor, mayor probabilidad de compra)",
|
| 11 |
+
"ExitRates": "Porcentaje de veces que el usuario sale del sitio desde una página específica",
|
| 12 |
+
"ProductRelated_Duration": "Tiempo total (segundos) que el usuario pasó en páginas de productos",
|
| 13 |
+
"ProductRelated": "Cantidad de páginas de productos visitadas",
|
| 14 |
+
"BounceRates": "Porcentaje de sesiones de una sola página (rebote)",
|
| 15 |
+
"Administrative_Duration": "Tiempo total (segundos) en páginas administrativas (información, contacto, etc.)",
|
| 16 |
+
"Administrative": "Cantidad de páginas administrativas visitadas"
|
| 17 |
+
}
|
| 18 |
+
|
| 19 |
+
def predict_shopper(PageValues, ExitRates, ProductRelated_Duration, ProductRelated, BounceRates, Administrative_Duration, Administrative):
|
| 20 |
+
X = np.array([[PageValues, ExitRates, ProductRelated_Duration, ProductRelated, BounceRates, Administrative_Duration, Administrative]])
|
| 21 |
+
pred = model.predict(X)[0]
|
| 22 |
+
proba = model.predict_proba(X)[0][1]
|
| 23 |
+
if pred == 1:
|
| 24 |
+
result = f"✅ El cliente probablemente COMPRARÁ (confianza: {proba:.2%})"
|
| 25 |
+
else:
|
| 26 |
+
result = f"❌ El cliente probablemente NO comprará (confianza: {1-proba:.2%})"
|
| 27 |
+
return result
|
| 28 |
+
|
| 29 |
+
description = """
|
| 30 |
+
# 🛒 ¿Comprará tu cliente? - Demo Interactiva
|
| 31 |
+
|
| 32 |
+
Imagina que eres dueño de una tienda online. ¿Te gustaría saber si un visitante va a comprar o no? Este modelo analiza el comportamiento del usuario y predice la probabilidad de compra usando variables clave:
|
| 33 |
+
|
| 34 |
+
"""
|
| 35 |
+
for k, v in feature_descriptions.items():
|
| 36 |
+
description += f"- **{k}**: {v}\n"
|
| 37 |
+
description += """
|
| 38 |
+
|
| 39 |
+
Completa los campos con los datos de un cliente y descubre la predicción. ¡Ideal para dueños de e-commerce, marketing y analítica!
|
| 40 |
+
"""
|
| 41 |
+
|
| 42 |
+
inputs = [
|
| 43 |
+
gr.Number(label="PageValues", info=feature_descriptions["PageValues"], value=0.0, minimum=0),
|
| 44 |
+
gr.Number(label="ExitRates", info=feature_descriptions["ExitRates"], value=0.0, minimum=0, maximum=1),
|
| 45 |
+
gr.Number(label="ProductRelated_Duration", info=feature_descriptions["ProductRelated_Duration"], value=0.0, minimum=0),
|
| 46 |
+
gr.Number(label="ProductRelated", info=feature_descriptions["ProductRelated"], value=0, minimum=0),
|
| 47 |
+
gr.Number(label="BounceRates", info=feature_descriptions["BounceRates"], value=0.0, minimum=0, maximum=1),
|
| 48 |
+
gr.Number(label="Administrative_Duration", info=feature_descriptions["Administrative_Duration"], value=0.0, minimum=0),
|
| 49 |
+
gr.Number(label="Administrative", info=feature_descriptions["Administrative"], value=0, minimum=0)
|
| 50 |
+
]
|
| 51 |
+
|
| 52 |
+
example = [2.5, 0.02, 120.0, 5, 0.01, 30.0, 1]
|
| 53 |
+
|
| 54 |
+
gr.Interface(
|
| 55 |
+
fn=predict_shopper,
|
| 56 |
+
inputs=inputs,
|
| 57 |
+
outputs=gr.Textbox(label="Predicción"),
|
| 58 |
+
title="¿Comprará tu cliente?",
|
| 59 |
+
description=description,
|
| 60 |
+
examples=[example],
|
| 61 |
+
theme="soft",
|
| 62 |
+
allow_flagging="never"
|
| 63 |
+
).launch()
|
final_pipe_less.pkl
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:4099b620f6cdc851f45fcdc73a4582e4b9c8fe3f1cb391e9c6986ced70d662d6
|
| 3 |
+
size 4053063
|
requirements.txt
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
gradio==4.26.0
|
| 2 |
+
joblib
|
| 3 |
+
scikit-learn
|
| 4 |
+
numpy
|