3v324v23 commited on
Commit
e0ba984
1 Parent(s): 040a27b

Add application file

Browse files
Files changed (2) hide show
  1. app.py +107 -0
  2. requirements.txt +4 -0
app.py ADDED
@@ -0,0 +1,107 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ mr = project.get_model_registry()
13
+ model = mr.get_model("titanic_modal", version=1)
14
+ model_dir = model.download()
15
+ model = joblib.load(model_dir + "/titanic_model.pkl")
16
+
17
+
18
+ def titanic(pclass, sex, age, fare, embarked, familysize, appellation, cabin):
19
+ input_list = []
20
+ # PClass
21
+ input_list.append(int(pclass))
22
+
23
+ # Gender
24
+ if sex == "Male":
25
+ input_list.append(0)
26
+ else:
27
+ input_list.append(1)
28
+
29
+ # Age
30
+ input_list.append(age)
31
+
32
+ # Fare
33
+ input_list.append(fare)
34
+
35
+ # Embarked
36
+ if embarked == "S":
37
+ input_list.append(0)
38
+ elif embarked == "C":
39
+ input_list.append(1)
40
+ elif embarked == "Q":
41
+ input_list.append(2)
42
+
43
+ # Family Size
44
+ input_list.append(familysize)
45
+
46
+ # Appellation
47
+ if appellation == "master":
48
+ input_list.append(1).append(0).append(0).append(0).append(0).append(0)
49
+ elif appellation == "miss":
50
+ input_list.append(0).append(1).append(0).append(0).append(0).append(0)
51
+ elif appellation == "mr":
52
+ input_list.append(0).append(0).append(1).append(0).append(0).append(0)
53
+ elif appellation == "mrs":
54
+ input_list.append(0).append(0).append(0).append(1).append(0).append(0)
55
+ elif appellation == "officer":
56
+ input_list.append(0).append(0).append(0).append(0).append(1).append(0)
57
+ elif appellation == "royalty":
58
+ input_list.append(0).append(0).append(0).append(0).append(0).append(1)
59
+
60
+ # Cabin
61
+ if cabin == "A":
62
+ input_list.append(1).append(0).append(0).append(0).append(0).append(0).append(0).append(0).append(0)
63
+ elif cabin == "B":
64
+ input_list.append(0).append(1).append(0).append(0).append(0).append(0).append(0).append(0).append(0)
65
+ elif cabin == "C":
66
+ input_list.append(0).append(0).append(1).append(0).append(0).append(0).append(0).append(0).append(0)
67
+ elif cabin == "D":
68
+ input_list.append(0).append(0).append(0).append(1).append(0).append(0).append(0).append(0).append(0)
69
+ elif cabin == "E":
70
+ input_list.append(0).append(0).append(0).append(0).append(1).append(0).append(0).append(0).append(0)
71
+ elif cabin == "F":
72
+ input_list.append(0).append(0).append(0).append(0).append(0).append(1).append(0).append(0).append(0)
73
+ elif cabin == "G":
74
+ input_list.append(0).append(0).append(0).append(0).append(0).append(0).append(1).append(0).append(0)
75
+ elif cabin == "T":
76
+ input_list.append(0).append(0).append(0).append(0).append(0).append(0).append(0).append(1).append(0)
77
+ else:
78
+ input_list.append(0).append(0).append(0).append(0).append(0).append(0).append(0).append(0).append(1)
79
+
80
+
81
+ # 'res' is a list of predictions returned as the label.
82
+ res = model.predict(np.asarray(input_list).reshape(1, -1))
83
+ # We add '[0]' to the result of the transformed 'res', because 'res' is a list, and we only want
84
+ # the first element.
85
+ titanic_url = "https://github.com/Qinglin2000/ID2223" + str(res[0]) + ".png?raw=true"
86
+ img = Image.open(requests.get(titanic_url, stream=True).raw)
87
+ return img
88
+
89
+
90
+ demo = gr.Interface(
91
+ fn=titanic,
92
+ title="Titatnic Predictive Analytics",
93
+ description="Experiment with titanic dataset values.",
94
+ allow_flagging="never",
95
+ inputs=[
96
+ gr.Dropdown(choices=["1", "2", "3"], label="PClass", value="1"),
97
+ gr.Radio(choices=["Male", "Female"], label="Gender", value="Male"),
98
+ gr.inputs.Number(default=30.0, label="Age"),
99
+ gr.inputs.Number(default=40.99, label="Fare"),
100
+ gr.Dropdown(choices=["S","C","Q"], label="Embarked", value="S"),
101
+ gr.Number(label="Family Size", precision=0, value=1),
102
+ gr.Dropdown(choices=["master", "miss", "mr", "mrs", "officer", "royalty"], label="Appellation", value="master"),
103
+ gr.Dropdown(choices=["A", "B", "C", "D", "E", "F", "G", "T", "U"], label="Cabin", value="A"),
104
+ ],
105
+ outputs=gr.Image(type="pil"))
106
+
107
+ demo.launch()
requirements.txt ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ hopsworks
2
+ joblib
3
+ scikit-learn
4
+