Victorlopo21 commited on
Commit
46be7fe
1 Parent(s): 7d5f4dd

Upload app.py

Browse files
Files changed (1) hide show
  1. app.py +54 -0
app.py ADDED
@@ -0,0 +1,54 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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(api_key_value="4CY1rwa8iz8Yu6gG.TwayrYmsX4GQfhSp3LNKYTLvyFMfqAvnzNUQp5ae9K5HhfYxb5mcnLAutm1K18zV")
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 passenger(pclass, sex, family, groupedage):
20
+ input_list = []
21
+ input_list.append(pclass)
22
+ input_list.append(sex)
23
+ input_list.append(family)
24
+ input_list.append(groupedage)
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
+ if res[0] == 1:
30
+ passenger_url = "https://cdn.pixabay.com/photo/2018/08/02/18/58/survival-3580200_960_720.png"
31
+ else:
32
+ passenger_url = "https://pngimg.com/uploads/death/death_PNG55.png"
33
+
34
+ img = Image.open(requests.get(passenger_url, stream=True).raw)
35
+ return img
36
+ #return res[0]
37
+
38
+
39
+ demo_titanic = gr.Interface(
40
+ fn=passenger,
41
+ title="Titanic Predictive Analytics",
42
+ description="Experiment to predict if a passenger survived or died in the titanic",
43
+ allow_flagging="never",
44
+ inputs=[
45
+ gr.inputs.Number(default=1.0, label="Pclass (Min:1, Max=3"),
46
+ gr.inputs.Number(default=1.0, label="Sex (Female:0 and Male:1)"),
47
+ gr.inputs.Number(default=1.0, label="Family (Number of family members in the boat[0,7])"),
48
+ gr.inputs.Number(default=1.0, label="Age (Child:0, Adult:1 and Old:2)")
49
+ ],
50
+ outputs=gr.Image(type="pil"))
51
+
52
+ #outputs=gr.Label(num_top_classes=2)
53
+ demo_titanic.launch()
54
+