howlbz commited on
Commit
8a4966f
1 Parent(s): ca14e6a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +51 -0
app.py CHANGED
@@ -0,0 +1,51 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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="0rdWXlLgEd3mkGOg.iRZ7TtAkWGPlJHNQcAEph6Qbokoaq7QTBRI9ckwWUki8tIYGyBvrKhJvtLoUOGQ4")
10
+ fs = project.get_feature_store()
11
+
12
+ mr = project.get_model_registry()
13
+ model = mr.get_model("titanic_modal", version=1)
14
+ model_dir = model.download()
15
+ model = joblib.load(model_dir + "/titanic_model.pkl")
16
+
17
+
18
+ def titanic(Pclass, Sex, Age, SibSp):
19
+ input_list = []
20
+ input_list.append(Pclass)
21
+ input_list.append(Sex)
22
+ input_list.append(Age)
23
+ input_list.append(SibSp)
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
+ # flower_url = "https://raw.githubusercontent.com/featurestoreorg/serverless-ml-course/main/src/01-module/assets/" + res[0] + ".png"
29
+ # img = Image.open(requests.get(flower_url, stream=True).raw)
30
+ # return img
31
+ if (res[0] == 0):
32
+ result = "I'm sorry, the person is dead"
33
+ else:
34
+ result = "Awesome, the person is survived!!!!!!"
35
+ return result
36
+
37
+
38
+ demo = gr.Interface(
39
+ fn=titanic,
40
+ title="Titanic Predictive Analytics",
41
+ description="Experiment with Passenger class/Sex/Age/SibSp to predict if the person is survived or not.",
42
+ allow_flagging="never",
43
+ inputs=[
44
+ gr.inputs.Number(default=1.0, label="Pclass (Flight class 1/2/3)"),
45
+ gr.inputs.Number(default=1.0, label="Sex (male=1/female=2)"),
46
+ gr.inputs.Number(default=1.0, label="Age (in years)"),
47
+ gr.inputs.Number(default=1.0, label="SibSp (number of siblings)"),
48
+ ],
49
+ outputs=gr.Textbox(label="Result: "))
50
+
51
+ demo.launch()