vishalned commited on
Commit
f7fe1e5
1 Parent(s): 9a1aba0
Files changed (1) hide show
  1. app.py +51 -0
app.py ADDED
@@ -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="otd1BvtKwvlF8OC1.Y8Kyt1QpZqDPMRNPIF3KvVGuFJpRdxIy39879ueQwymTgSDUU9vWKFMOnBqsyxfk")
10
+ fs = project.get_feature_store()
11
+ #q
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
+ def titanic(pclass, sex, age, sibsp, parch, fare, embarked):
19
+ input_list = []
20
+ input_list.append(pclass)
21
+ input_list.append(sex)
22
+ input_list.append(age)
23
+ input_list.append(sibsp)
24
+ input_list.append(parch)
25
+ input_list.append(fare)
26
+ input_list.append(embarked)
27
+ # 'res' is a list of predictions returned as the label.
28
+ res = model.predict(np.asarray(input_list).reshape(1, -1))
29
+ # We add '[0]' to the result of the transformed 'res', because 'res' is a list, and we only want
30
+ # the first element.
31
+ return res[0]
32
+
33
+
34
+ demo = gr.Interface(
35
+ fn=titanic,
36
+ title="Titanic Predictive Analytics",
37
+ description="Experiment to predict if a passenger survived the Titanic disaster",
38
+ allow_flagging="never",
39
+ inputs=[
40
+ gr.inputs.Number(default=1.0, label="PClass"),
41
+ gr.inputs.Number(default=1.0, label="Sex: Female = 0, Male = 1"),
42
+ gr.inputs.Number(default=1.0, label="Age"),
43
+ gr.inputs.Number(default=1.0, label="SibSp"),
44
+ gr.inputs.Number(default=1.0, label="Parch"),
45
+ gr.inputs.Number(default=1.0, label="Fare"),
46
+ gr.inputs.Number(default=1.0, label="Embarked: S = 0, C = 1, Q = 2"),
47
+ ],
48
+ outputs=gr.Textbox())
49
+
50
+ demo.launch()
51
+