CsanadT commited on
Commit
64cde8b
1 Parent(s): 31fbcef

Upload 2 files

Browse files
Files changed (2) hide show
  1. app.py +48 -0
  2. requirements.txt +1 -0
app.py ADDED
@@ -0,0 +1,48 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import numpy as np
3
+ import requests
4
+
5
+ import hopsworks
6
+ import joblib
7
+
8
+ project = hopsworks.login()
9
+ fs = project.get_feature_store()
10
+
11
+
12
+ mr = project.get_model_registry()
13
+ model = mr.get_model("titanic_modal", version=3)
14
+ model_dir = model.download()
15
+ model = joblib.load(model_dir + "/titanic_model.pkl")
16
+
17
+
18
+ def titanic(age, sex, pclass, fare):
19
+ input_list = []
20
+ input_list.append(age)
21
+ input_list.append(sex)
22
+ input_list.append(pclass)
23
+ input_list.append(fare)
24
+ # 'res' is a list of predictions returned as the label.
25
+ res = model.predict(np.asarray(input_list).reshape(1, -1))
26
+ # We add '[0]' to the result of the transformed 'res', because 'res' is a list, and we only want
27
+ # the first element.
28
+ if res == 0:
29
+ output = "This individual probably survived the crash."
30
+ else:
31
+ output = "This individual unfortunately probably did not survive the crash."
32
+ return output
33
+
34
+ demo = gr.Interface(
35
+ fn=titanic,
36
+ title="Titanic survivor analytics",
37
+ description="Experiment with personal data to predict whether a person would survive the Titanic",
38
+ allow_flagging="never",
39
+ inputs=[
40
+ gr.inputs.Number(default=30.0, label=" Age "),
41
+ gr.inputs.Number(default=1, label=" Sex (0 = Female, 1 = Male) "),
42
+ gr.inputs.Number(default=2, label=" Ticket class (1 = first, 2 = second, 3 = third) "),
43
+ gr.inputs.Number(default=1.0, label=" Passenger fare ()"),
44
+ ],
45
+ outputs=gr.outputs.Textbox(label='Prediction'))
46
+
47
+ demo.launch()
48
+
requirements.txt ADDED
@@ -0,0 +1 @@
 
 
1
+ hopsworks