vishalned commited on
Commit
64e5cd7
1 Parent(s): 10406e5
Files changed (1) hide show
  1. app.py +71 -52
app.py CHANGED
@@ -1,19 +1,34 @@
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="rA4UUi0EGe9o2Lpo.xoqva15Ia7l8Fz7PBFrFTV4WjSG8B1aQofJlVp3oV3Xp0iHyFTzw5ybC4OapypyU")
10
- # fs = project.get_feature_store()
11
 
 
 
 
 
12
 
13
- # mr = project.get_model_registry()
14
- # model = mr.get_model("iris_modal", version=1)
15
- # model_dir = model.download()
16
- # model = joblib.load(model_dir + "/iris_model.pkl")
 
 
 
 
 
 
 
 
 
 
17
 
18
 
19
  # def iris(sepal_length, sepal_width, petal_length, petal_width):
@@ -30,49 +45,53 @@
30
  # img = Image.open(requests.get(flower_url, stream=True).raw)
31
  # return img
32
 
33
- # demo = gr.Interface(
34
- # fn=iris,
35
- # title="Iris Flower Predictive Analytics",
36
- # description="Experiment with sepal/petal lengths/widths to predict which flower it is.",
37
- # allow_flagging="never",
38
- # inputs=[
39
- # gr.inputs.Number(default=1.0, label="sepal length (cm)"),
40
- # gr.inputs.Number(default=1.0, label="sepal width (cm)"),
41
- # gr.inputs.Number(default=1.0, label="petal length (cm)"),
42
- # gr.inputs.Number(default=1.0, label="petal width (cm)"),
43
- # ],
44
- # outputs=gr.Image(type="pil"))
 
 
 
45
 
46
- # demo.launch()
47
 
48
- import gradio as gr
49
- from PIL import Image
50
- import hopsworks
 
51
 
52
- project = hopsworks.login(api_key_value="rA4UUi0EGe9o2Lpo.xoqva15Ia7l8Fz7PBFrFTV4WjSG8B1aQofJlVp3oV3Xp0iHyFTzw5ybC4OapypyU")
53
- fs = project.get_feature_store()
54
- #h
55
- dataset_api = project.get_dataset_api()
56
 
57
- dataset_api.download("Resources/images/latest_iris.png")
58
- dataset_api.download("Resources/images/actual_iris.png")
59
- dataset_api.download("Resources/images/df_recent.png")
60
- dataset_api.download("Resources/images/confusion_matrix.png")
61
 
62
- with gr.Blocks() as demo:
63
- with gr.Row():
64
- with gr.Column():
65
- gr.Label("Today's Predicted Image")
66
- input_img = gr.Image("latest_iris.png", elem_id="predicted-img")
67
- with gr.Column():
68
- gr.Label("Today's Actual Image")
69
- input_img = gr.Image("actual_iris.png", elem_id="actual-img")
70
- with gr.Row():
71
- with gr.Column():
72
- gr.Label("Recent Prediction History")
73
- input_img = gr.Image("df_recent.png", elem_id="recent-predictions")
74
- with gr.Column():
75
- gr.Label("Confusion Maxtrix with Historical Prediction Performance")
76
- input_img = gr.Image("confusion_matrix.png", elem_id="confusion-matrix")
77
 
78
- demo.launch()
 
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="rA4UUi0EGe9o2Lpo.xoqva15Ia7l8Fz7PBFrFTV4WjSG8B1aQofJlVp3oV3Xp0iHyFTzw5ybC4OapypyU")
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
+ 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
  # def iris(sepal_length, sepal_width, petal_length, petal_width):
 
45
  # img = Image.open(requests.get(flower_url, stream=True).raw)
46
  # return img
47
 
48
+ demo = gr.Interface(
49
+ fn=titanic,
50
+ title="Titanic Predictive Analytics",
51
+ description="Experiment to predict if a passenger survived the Titanic disaster",
52
+ allow_flagging="never",
53
+ inputs=[
54
+ gr.inputs.Number(default=1.0, label="PClass"),
55
+ gr.inputs.Number(default=1.0, label="Sex"),
56
+ gr.inputs.Number(default=1.0, label="Age"),
57
+ gr.inputs.Number(default=1.0, label="SibSp"),
58
+ gr.inputs.Number(default=1.0, label="Parch"),
59
+ gr.inputs.Number(default=1.0, label="Fare"),
60
+ gr.inputs.Number(default=1.0, label="Embarked")
61
+ ],
62
+ outputs=gr.Textbox())
63
 
64
+ demo.launch()
65
 
66
+ # monitoring part of the code
67
+ # import gradio as gr
68
+ # from PIL import Image
69
+ # import hopsworks
70
 
71
+ # project = hopsworks.login(api_key_value="rA4UUi0EGe9o2Lpo.xoqva15Ia7l8Fz7PBFrFTV4WjSG8B1aQofJlVp3oV3Xp0iHyFTzw5ybC4OapypyU")
72
+ # fs = project.get_feature_store()
73
+ # #h
74
+ # dataset_api = project.get_dataset_api()
75
 
76
+ # dataset_api.download("Resources/images/latest_iris.png")
77
+ # dataset_api.download("Resources/images/actual_iris.png")
78
+ # dataset_api.download("Resources/images/df_recent.png")
79
+ # dataset_api.download("Resources/images/confusion_matrix.png")
80
 
81
+ # with gr.Blocks() as demo:
82
+ # with gr.Row():
83
+ # with gr.Column():
84
+ # gr.Label("Today's Predicted Image")
85
+ # input_img = gr.Image("latest_iris.png", elem_id="predicted-img")
86
+ # with gr.Column():
87
+ # gr.Label("Today's Actual Image")
88
+ # input_img = gr.Image("actual_iris.png", elem_id="actual-img")
89
+ # with gr.Row():
90
+ # with gr.Column():
91
+ # gr.Label("Recent Prediction History")
92
+ # input_img = gr.Image("df_recent.png", elem_id="recent-predictions")
93
+ # with gr.Column():
94
+ # gr.Label("Confusion Maxtrix with Historical Prediction Performance")
95
+ # input_img = gr.Image("confusion_matrix.png", elem_id="confusion-matrix")
96
 
97
+ # demo.launch()