Update app.py
Browse files
app.py
CHANGED
@@ -1,33 +1,37 @@
|
|
1 |
-
import gradio as gr
|
2 |
-
|
3 |
-
import
|
4 |
-
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
#
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
#
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
gr.
|
28 |
-
|
29 |
-
|
30 |
-
)
|
31 |
-
|
32 |
-
|
33 |
-
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import numpy as np
|
3 |
+
import joblib
|
4 |
+
|
5 |
+
# Cargar el modelo entrenado
|
6 |
+
model = joblib.load('titanic.pkl')
|
7 |
+
|
8 |
+
def predict_survival(sex, age, fare, pclass, sibsp):
|
9 |
+
# Convertir entradas a formato num茅rico y ajustar seg煤n el modelo
|
10 |
+
# Asumimos que 'Masculino' = 1, 'Femenino' = 0
|
11 |
+
sex = 1 if sex == "Masculino" else 0
|
12 |
+
|
13 |
+
# Preparar el array con las caracter铆sticas en el orden correcto
|
14 |
+
input_features = np.array([[sex, age, fare, pclass, sibsp]])
|
15 |
+
|
16 |
+
# Hacer la predicci贸n usando el modelo
|
17 |
+
prediction = model.predict(input_features)
|
18 |
+
|
19 |
+
# Retornar el resultado en forma legible
|
20 |
+
result = 'Sobrevive' if prediction[0] == 1 else 'No sobrevive'
|
21 |
+
return result
|
22 |
+
|
23 |
+
# Definir la interfaz de Gradio
|
24 |
+
iface = gr.Interface(
|
25 |
+
fn=predict_survival,
|
26 |
+
inputs=[
|
27 |
+
gr.components.Dropdown(choices=["Masculino", "Femenino"], label="Sexo"),
|
28 |
+
gr.components.Slider(minimum=0, maximum=100, step=1, default=28, label="Edad"),
|
29 |
+
gr.components.Slider(minimum=0, maximum=512, step=1, default=33, label="Tarifa"),
|
30 |
+
gr.components.Dropdown(choices=[1, 2, 3], label="Clase del Pasajero"),
|
31 |
+
gr.components.Slider(minimum=0, maximum=8, step=1, default=0, label="Hermanos/C贸nyuges a bordo")
|
32 |
+
],
|
33 |
+
outputs=gr.components.Textbox(label="Predicci贸n de Supervivencia")
|
34 |
+
)
|
35 |
+
|
36 |
+
# Lanzar la aplicaci贸n
|
37 |
+
iface.launch()
|