nandovallec commited on
Commit
593b89c
1 Parent(s): c037a26
Files changed (3) hide show
  1. .hw_api_key +1 -0
  2. app.py +67 -0
  3. requirements.txt +3 -0
.hw_api_key ADDED
@@ -0,0 +1 @@
 
 
1
+ Ri2FZ9IsPDNHnuly.uYd6MFsZTxbZSQ23ssaVzdzQtJNAS8fBMQ5owgIM9Wr5hUQ7Qj7Yhe7wOtPOnIDp
app.py ADDED
@@ -0,0 +1,67 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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=2)
15
+ model_dir = model.download()
16
+ model = joblib.load(model_dir + "/titanic_model.pkl")
17
+
18
+
19
+ def titanic_passanger(age, sex, sibsp, parch, fare, embarked, pclass):
20
+ input_list = []
21
+ sex_value = 1 if sex=='female' else 0
22
+ pclass_value = int(pclass)
23
+ if embarked == 'S':
24
+ embarked_value = 0
25
+ elif embarked == 'C':
26
+ embarked_value = 1
27
+ else:
28
+ embarked_value = 2
29
+ input_list.append(pclass_value)
30
+ input_list.append(sex_value)
31
+ input_list.append(age)
32
+ input_list.append(sibsp)
33
+ input_list.append(parch)
34
+ input_list.append(fare)
35
+ input_list.append(embarked_value)
36
+
37
+
38
+ # 'res' is a list of predictions returned as the label.
39
+ res = model.predict(np.asarray(input_list).reshape(1, -1))
40
+ # We add '[0]' to the result of the transformed 'res', because 'res' is a list, and we only want
41
+ # the first element.
42
+ img_urls=["https://uxwing.com/wp-content/themes/uxwing/download/health-sickness-organs/skull-icon.png", "https://uxwing.com/wp-content/themes/uxwing/download/emoji-emoticon/happy-icon.png"]
43
+ img_url = img_urls[res[0]]
44
+ img = Image.open(requests.get(img_url, stream=True).raw)
45
+ return img
46
+
47
+ demo = gr.Interface(
48
+ fn=titanic_passanger,
49
+ title="Titanic Survivor Predictive Analytics",
50
+ description="Experiment with the features to predict survivor status.",
51
+ allow_flagging="never",
52
+ inputs=[
53
+ gr.inputs.Number(default=22.0, label="Age"),
54
+ gr.inputs.Radio(['female', 'male'], label="Sex"),
55
+
56
+ gr.inputs.Number(default=1.0, label="Number of siblings and spouses aboard"),
57
+ gr.inputs.Number(default=1.0, label="Number of parents and children aboard"),
58
+
59
+ gr.inputs.Number(default=1.0, label="Fare"),
60
+
61
+ gr.inputs.Radio(['S', 'C', 'Q'], label="Port embarked"),
62
+ gr.inputs.Radio(['1', '2', '3'], label="Ticket class"),
63
+ ],
64
+ outputs=gr.Image(type="pil"))
65
+
66
+ demo.launch()
67
+
requirements.txt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ hopsworks
2
+ joblib
3
+ scikit-learn