ZinebSN commited on
Commit
37a24ba
·
1 Parent(s): 6baced9

Upload app.py

Browse files
Files changed (1) hide show
  1. app.py +73 -0
app.py ADDED
@@ -0,0 +1,73 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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=5)
15
+ model_dir = model.download()
16
+ model = joblib.load(model_dir + "/titanic_model.pkl")
17
+
18
+
19
+ def titanic(sex, age, pclass, parch, embarked):
20
+ input_list = []
21
+ if pclass=='1 First Class':
22
+ input_list.append(1)
23
+ elif pclass=='2 Second Class':
24
+ input_list.append(2)
25
+ else:
26
+ input_list.append(3)
27
+
28
+ if sex=='Female':
29
+ input_list.append(1)
30
+ else:
31
+ input_list.append(0)
32
+
33
+
34
+ input_list.append(age)
35
+ input_list.append(parch)
36
+
37
+ if embarked=='C (Cherbourg)':
38
+
39
+ input_list.append(2)
40
+ elif embarked=='S (Southampton)':
41
+
42
+ input_list.append(1)
43
+ else:
44
+
45
+ input_list.append(0)
46
+
47
+ # 'res' is a list of predictions returned as the label.
48
+ res = model.predict(np.asarray(input_list,dtype=object).reshape(1,-1))
49
+ # We add '[0]' to the result of the transformed 'res', because 'res' is a list, and we only want
50
+ # the first element.
51
+
52
+
53
+ flower_url = "https://raw.githubusercontent.com/avatar46/ID2223_lab1/main/images/" + str(res[0]) + ".png"
54
+ img = Image.open(requests.get(flower_url, stream=True).raw)
55
+ return img
56
+
57
+ demo = gr.Interface(
58
+ fn=titanic,
59
+ title="Titanic Survival Predictive Analytics",
60
+ description="Experiment with different entries to predict if the person will survive.",
61
+ allow_flagging="never",
62
+ ### Create user interface with 5 inputs
63
+ inputs=[
64
+ gr.inputs.Radio(default='Female', label="Gender", choices=['Female','Male']),
65
+ gr.inputs.Slider(0,150,label='Age'),
66
+ gr.inputs.Radio(default='1 First Class', label="Passenger Class ", choices=['1 First Class', '2 Second Class', '3 Third Class']),
67
+ gr.inputs.Number(default=1.0, label="Parch: # of parents / children aboard the Titanic "),
68
+ gr.inputs.Radio(default='C (Cherbourg)', label="Embarkation Port", choices=['C (Cherbourg)', 'Q (Queenstown)', 'S (Southampton)']),
69
+ ],
70
+ outputs=gr.Image(type="pil"))
71
+
72
+ demo.launch()
73
+