Upload 2 files
Browse files- app.py +57 -0
- requirements.txt +3 -0
app.py
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import numpy as np
|
| 3 |
+
from PIL import Image
|
| 4 |
+
import requests
|
| 5 |
+
|
| 6 |
+
import hopsworks
|
| 7 |
+
import joblib
|
| 8 |
+
|
| 9 |
+
project = hopsworks.login()
|
| 10 |
+
fs = project.get_feature_store()
|
| 11 |
+
|
| 12 |
+
|
| 13 |
+
mr = project.get_model_registry()
|
| 14 |
+
model = mr.get_model("titanic_modal", version=1)
|
| 15 |
+
model_dir = model.download()
|
| 16 |
+
model = joblib.load(model_dir + "/titanic_model.pkl")
|
| 17 |
+
|
| 18 |
+
|
| 19 |
+
def titanic(pclass, sex, age, sibsp, parch, fare, cabin):
|
| 20 |
+
input_list = []
|
| 21 |
+
input_list.append(pclass)
|
| 22 |
+
input_list.append(sex)
|
| 23 |
+
input_list.append(age)
|
| 24 |
+
input_list.append(sibsp)
|
| 25 |
+
input_list.append(parch)
|
| 26 |
+
input_list.append(fare)
|
| 27 |
+
input_list.append(cabin)
|
| 28 |
+
|
| 29 |
+
res = model.predict(np.asarray(input_list).reshape(1, -1))
|
| 30 |
+
|
| 31 |
+
if (res[0] == 1):
|
| 32 |
+
return "Passenger survived!"
|
| 33 |
+
else:
|
| 34 |
+
return "Passenger did not survive."
|
| 35 |
+
|
| 36 |
+
|
| 37 |
+
demo = gr.Interface(
|
| 38 |
+
fn=titanic,
|
| 39 |
+
title="Titanic Passenger Survival Predictive Analysis",
|
| 40 |
+
description="Experiment with the variables below to determine if a passenger would survive the Titanic",
|
| 41 |
+
allow_flagging="never",
|
| 42 |
+
inputs=[
|
| 43 |
+
gr.inputs.Number(
|
| 44 |
+
default=1, label="Ticket class (1: upper, 2: middle, 3: lower)"),
|
| 45 |
+
gr.inputs.Number(default=1, label="Gender (1: female, 0: male)"),
|
| 46 |
+
gr.inputs.Number(
|
| 47 |
+
default=1, label="Age (0: child, 1: teenager, 2: young adult, 3: adult, 4: old)"),
|
| 48 |
+
gr.inputs.Number(default=1, label="Siblings/spouse onboard"),
|
| 49 |
+
gr.inputs.Number(default=1, label="Parents/children onboard"),
|
| 50 |
+
gr.inputs.Number(default=1, label="Passenger fare ($)"),
|
| 51 |
+
gr.inputs.Number(
|
| 52 |
+
default=1, label="Cabin deck (0-7 corresponds to A-G)")
|
| 53 |
+
],
|
| 54 |
+
|
| 55 |
+
outputs=gr.Textbox())
|
| 56 |
+
|
| 57 |
+
demo.launch()
|
requirements.txt
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
hopsworks
|
| 2 |
+
joblib
|
| 3 |
+
scikit-learn
|