kk90ujhun commited on
Commit
6ec3656
1 Parent(s): d6ae38f

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +53 -0
app.py ADDED
@@ -0,0 +1,53 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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=10)
15
+ model_dir = model.download()
16
+ model = joblib.load(model_dir + "/titanic_model.pkl")
17
+
18
+ def titanic(age, embarked, fare, parch, pclass, sex, sibsp):
19
+ input_list = []
20
+ input_list.append(age)
21
+ input_list.append(embarked)
22
+ input_list.append(fare)
23
+ input_list.append(parch)
24
+ input_list.append(pclass)
25
+ input_list.append(sex)
26
+ input_list.append(sibsp)
27
+ # 'res' is a list of predictions returned as the label.
28
+ res = model.predict(np.asarray(input_list).reshape(1, -1))
29
+ # We add '[0]' to the result of the transformed 'res', because 'res' is a list, and we only want the first element.
30
+ # flower_url = "https://raw.githubusercontent.com/featurestoreorg/serverless-ml-course/main/src/01-module/assets/" + res[0] + ".png"
31
+ # img = Image.open(requests.get(flower_url, stream=True).raw)
32
+ if res == [1]:
33
+ res = 'survive'
34
+ else:
35
+ res = 'die'
36
+ return res
37
+
38
+ demo = gr.Interface(
39
+ fn=titanic,
40
+ title="Titanic Survivor Predictive Analytics",
41
+ description="Experiment with age/embarked/fare/parch/pclass/sex/sibsp to predict if the passenger survived.",
42
+ allow_flagging="never",
43
+ inputs=[
44
+ gr.inputs.Number(default=2.0, label="age"),
45
+ gr.inputs.Number(default=1.0, label="embarked (0 for S, 1 for C, 2 for Q)"),
46
+ gr.inputs.Number(default=35.0, label="fare"),
47
+ gr.inputs.Number(default=1.0, label="parch"),
48
+ gr.inputs.Number(default=1.0, label="pclass"),
49
+ gr.inputs.Number(default=1.0, label="sex (0 for male, 1 for male)"),
50
+ gr.inputs.Number(default=1.0, label="sibsp")
51
+ ],
52
+ outputs=gr.Textbox())
53
+ demo.launch()