Upload app.py
Browse files
app.py
CHANGED
@@ -1,31 +1,53 @@
|
|
1 |
import gradio as gr
|
|
|
2 |
from PIL import Image
|
|
|
|
|
3 |
import hopsworks
|
|
|
4 |
|
5 |
-
project = hopsworks.login(
|
6 |
fs = project.get_feature_store()
|
7 |
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
30 |
|
31 |
demo.launch()
|
|
|
|
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 |
+
#HwJaWmtvaCzFra3g.89QYueFGuScRnJkiepzG2tiWtKSrqNHCCJrnVie9fwhIMeJxRUpAGAT7mF36MDMv
|
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):
|
20 |
+
input_list = []
|
21 |
+
input_list.append(Pclass)
|
22 |
+
input_list.append(Sex)
|
23 |
+
input_list.append(Age)
|
24 |
+
input_list.append(SibSp)
|
25 |
+
# 'res' is a list of predictions returned as the label.
|
26 |
+
res = model.predict(np.asarray(input_list).reshape(1, -1))
|
27 |
+
# We add '[0]' to the result of the transformed 'res', because 'res' is a list, and we only want
|
28 |
+
# the first element.
|
29 |
+
# flower_url = "https://raw.githubusercontent.com/featurestoreorg/serverless-ml-course/main/src/01-module/assets/" + res[0] + ".png"
|
30 |
+
# img = Image.open(requests.get(flower_url, stream=True).raw)
|
31 |
+
# return img
|
32 |
+
if (res[0] == 0):
|
33 |
+
result = "I'm sorry, the person is dead"
|
34 |
+
else:
|
35 |
+
result = "Awesome, the person is survived!!!!!!"
|
36 |
+
return result
|
37 |
+
|
38 |
+
|
39 |
+
demo = gr.Interface(
|
40 |
+
fn=titanic,
|
41 |
+
title="Titanic Predictive Analytics",
|
42 |
+
description="Experiment with Passenger class/Sex/Age/SibSp to predict if the person is survived or not.",
|
43 |
+
allow_flagging="never",
|
44 |
+
inputs=[
|
45 |
+
gr.inputs.Number(default=1.0, label="Pclass (Flight class 1/2/3)"),
|
46 |
+
gr.inputs.Number(default=1.0, label="Sex (male=1/female=2)"),
|
47 |
+
gr.inputs.Number(default=1.0, label="Age (in years)"),
|
48 |
+
gr.inputs.Number(default=1.0, label="SibSp (number of siblings)"),
|
49 |
+
],
|
50 |
+
outputs=gr.Textbox(label="Result: "))
|
51 |
|
52 |
demo.launch()
|
53 |
+
|