humeur commited on
Commit
b22e39b
1 Parent(s): 95121d4

Initial commit

Browse files
Files changed (1) hide show
  1. app.py +52 -0
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 titanic(Sex, Age, Pclass, Fare, Parch, SibSp, Embarked):
20
+ input_list = []
21
+ input_list.append(Sex)
22
+ input_list.append(Age)
23
+ input_list.append(Pclass)
24
+ input_list.append(Fare)
25
+ input_list.append(Parch)
26
+ input_list.append(SibSp)
27
+ input_list.append(Embarked)
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
+ pic_url = "https://raw.githubusercontent.com/backgroundhumeur/id2223_labs/main/src/titanic/assets/titanic_" + res[0] + ".jpg"
33
+ img = Image.open(requests.get(pic_url, stream=True).raw)
34
+ return img
35
+
36
+ demo = gr.Interface(
37
+ fn=titanic,
38
+ title="Titanic Passenger Survival Predictive Analytics",
39
+ description="Experiment with different characteristics of a passenger to predict whether he would have survived if he were aboard the titanic.",
40
+ allow_flagging="never",
41
+ inputs=[
42
+ gr.inputs.Dropdown(choices=["male","female"], value="male", label="Sex"),
43
+ gr.inputs.Number(default=28.0, label="Age", precision=0),
44
+ gr.inputs.Slider(minimum=1.0,maximum=3.0,value=3.0,step=1.0, label="Ticket class (1st to 3rd)"),
45
+ gr.inputs.Number(default=14.4542, label="Fare ($)"),
46
+ gr.inputs.Number(default=0.0, label="Number of parents/children aboard", precision=0),
47
+ gr.inputs.Number(default=0.0, label="Number of siblings/spouses aboard", precision=0),
48
+ gr.inputs.Dropdown(choices=["S","C", "Q"], value="C", label="Port of Embarkation")
49
+ ],
50
+ outputs=gr.Image(type="pil"))
51
+
52
+ demo.launch()