Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,50 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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=2)
|
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,Embarked):
|
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(Embarked)
|
28 |
+
# 'res' is a list of predictions returned as the label.
|
29 |
+
res = model.predict(np.asarray(input_list).reshape(1, -1))
|
30 |
+
return res
|
31 |
+
|
32 |
+
demo = gr.Interface(
|
33 |
+
fn=titanic,
|
34 |
+
title="Titanic Survival Predictive Analytics",
|
35 |
+
description="Experiment with passengers information to predict whether they can survive in titanic.",
|
36 |
+
allow_flagging="never",
|
37 |
+
inputs=[
|
38 |
+
gr.inputs.Number(default=1.0, label="Class [0, 1, 2]"),
|
39 |
+
gr.inputs.Number(default=1.0, label="Sex [0(male), 1(female)]"),
|
40 |
+
gr.inputs.Number(default=1.0, label="Age [y/o]"),
|
41 |
+
gr.inputs.Number(default=1.0, label="sibsp [0-5]]"),
|
42 |
+
gr.inputs.Number(default=1.0, label="Parch [0-6]]"),
|
43 |
+
gr.inputs.Number(default=1.0, label="Fare [USD]"),
|
44 |
+
gr.inputs.Number(default=1.0, label="Embarked [0 (S), 1 (C), 2 (Q)]"),
|
45 |
+
],
|
46 |
+
outputs=gr.Text(value="none")
|
47 |
+
)
|
48 |
+
|
49 |
+
demo.launch()
|
50 |
+
|