Upload 3 files
Browse files- main.py +33 -0
- requeriments.txt +4 -0
- titanic.pkl +3 -0
main.py
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
from sklearn.linear_model import LogisticRegression
|
| 3 |
+
import numpy as np
|
| 4 |
+
import joblib
|
| 5 |
+
|
| 6 |
+
# Cargar tu modelo entrenado; aseg煤rate de tener el modelo guardado como 'model_5_features.pkl'
|
| 7 |
+
# Si no tienes el modelo guardado, deber铆as entrenarlo y guardarlo con joblib:
|
| 8 |
+
# joblib.dump(model_5_features, 'model_5_features.pkl')
|
| 9 |
+
|
| 10 |
+
model = joblib.load('titanic.pkl')
|
| 11 |
+
|
| 12 |
+
def predict_survival(sex, age, fare, pclass, sibsp):
|
| 13 |
+
# Convertir entradas a array 2D (1 fila con n columnas)
|
| 14 |
+
input_array = np.array([[sex, age, fare, pclass, sibsp]])
|
| 15 |
+
prediction = model.predict(input_array)
|
| 16 |
+
result = 'Sobrevive' if prediction[0] == 1 else 'No sobrevive'
|
| 17 |
+
return result
|
| 18 |
+
|
| 19 |
+
# Crear la interfaz de Gradio
|
| 20 |
+
iface = gr.Interface(
|
| 21 |
+
fn=predict_survival,
|
| 22 |
+
inputs=[
|
| 23 |
+
gr.inputs.Dropdown(choices=["Masculino", "Femenino"], label="Sexo"),
|
| 24 |
+
gr.inputs.Slider(minimum=0, maximum=100, step=1, default=28, label="Edad"),
|
| 25 |
+
gr.inputs.Slider(minimum=0, maximum=512, step=1, default=33, label="Tarifa"),
|
| 26 |
+
gr.inputs.Dropdown(choices=[1, 2, 3], label="Clase del Pasajero"),
|
| 27 |
+
gr.inputs.Slider(minimum=0, maximum=8, step=1, default=0, label="Hermanos/C贸nyuges a bordo")
|
| 28 |
+
],
|
| 29 |
+
outputs=gr.outputs.Textbox(label="Predicci贸n de Supervivencia")
|
| 30 |
+
)
|
| 31 |
+
|
| 32 |
+
# Ejecutar la interfaz
|
| 33 |
+
iface.launch()
|
requeriments.txt
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
gradio
|
| 2 |
+
scikit-learn
|
| 3 |
+
numpy
|
| 4 |
+
joblib
|
titanic.pkl
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:2ca3c12e5f33f25ca9f69237c5a50ace48f6e8f255fdc4d442544922d27030ce
|
| 3 |
+
size 894
|