Add application file
Browse files
app.py
ADDED
@@ -0,0 +1,52 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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 passenger(passengerid, survived, pclass,age, sex, sibsp,parch):
|
20 |
+
input_list = []
|
21 |
+
input_list.append(passengerid)
|
22 |
+
input_list.append(survived)
|
23 |
+
input_list.append(pclass)
|
24 |
+
input_list.append(age)
|
25 |
+
input_list.append(sex)
|
26 |
+
input_list.append(sibsp)
|
27 |
+
input_list.append(parch)
|
28 |
+
# 'res' is a list of predictions returned as the label.
|
29 |
+
res = model.predict(np.asarray(input_list).reshape(1, -1))
|
30 |
+
# We add '[0]' to the result of the transformed 'res', because 'res' is a list, and we only want
|
31 |
+
# the first element.
|
32 |
+
titanic_url = "https://raw.githubusercontent.com/AbyelT/ID2223-Scalable-ML-and-DL/main/Lab1/Titanic/assets/" + res[0] + ".png"
|
33 |
+
img = Image.open(requests.get(titanic_url, stream=True).raw)
|
34 |
+
return img
|
35 |
+
|
36 |
+
demo = gr.Interface(
|
37 |
+
fn=passenger,
|
38 |
+
title="Titanic Survival Predictive Analytics",
|
39 |
+
#description="Experiment with sepal/petal lengths/widths to predict which flower it is.",
|
40 |
+
allow_flagging="never",
|
41 |
+
inputs=[
|
42 |
+
gr.inputs.Number(default=1.0, label="passengerid"),
|
43 |
+
gr.inputs.Number(default=1.0, label="survived"),
|
44 |
+
gr.inputs.Number(default=1.0, label="pclass"),
|
45 |
+
gr.inputs.Number(default=1.0, label="age"),
|
46 |
+
gr.inputs.Number(default=1.0, label="sex"),
|
47 |
+
gr.inputs.Number(default=1.0, label="sibsp"),
|
48 |
+
gr.inputs.Number(default=1.0, label="parch"),
|
49 |
+
],
|
50 |
+
outputs=gr.Image(type="pil"))
|
51 |
+
|
52 |
+
demo.launch()
|