howlbz commited on
Commit
cc65c8e
1 Parent(s): b9d3c15

Upload app.py

Browse files
Files changed (1) hide show
  1. app.py +45 -23
app.py CHANGED
@@ -1,31 +1,53 @@
1
  import gradio as gr
 
2
  from PIL import Image
 
 
3
  import hopsworks
 
4
 
5
- project = hopsworks.login(api_key_value="U1TTeOPaUDFWhd6N.H604QVLj5yOFVPGeSrXsoFY2IKrGkdqR0iTzWMr22rZxXQrn5VoYKdb4fghqxTna")
6
  fs = project.get_feature_store()
7
 
8
- dataset_api = project.get_dataset_api()
9
-
10
- dataset_api.download("Resources/images/latest_passenger.png",overwrite=True)
11
- dataset_api.download("Resources/images/actual_passenger.png",overwrite=True)
12
- dataset_api.download("Resources/images/df_recent.png",overwrite=True)
13
- dataset_api.download("Resources/images/confusion_matrix.png",overwrite=True)
14
-
15
- with gr.Blocks() as demo:
16
- with gr.Row():
17
- with gr.Column():
18
- gr.Label("Today's Predicted Image")
19
- input_img = gr.Image("latest_passenger.png", elem_id="predicted-img")
20
- with gr.Column():
21
- gr.Label("Today's Actual Image")
22
- input_img = gr.Image("actual_passenger.png", elem_id="actual-img")
23
- with gr.Row():
24
- with gr.Column():
25
- gr.Label("Recent Prediction History")
26
- input_img = gr.Image("df_recent.png", elem_id="recent-predictions")
27
- with gr.Column():
28
- gr.Label("Confusion Maxtrix with Historical Prediction Performance")
29
- input_img = gr.Image("confusion_matrix.png", elem_id="confusion-matrix")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
30
 
31
  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()
10
  fs = project.get_feature_store()
11
 
12
+ #HwJaWmtvaCzFra3g.89QYueFGuScRnJkiepzG2tiWtKSrqNHCCJrnVie9fwhIMeJxRUpAGAT7mF36MDMv
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
+
19
+ def titanic(Pclass, Sex, Age, SibSp):
20
+ input_list = []
21
+ input_list.append(Pclass)
22
+ input_list.append(Sex)
23
+ input_list.append(Age)
24
+ input_list.append(SibSp)
25
+ # 'res' is a list of predictions returned as the label.
26
+ res = model.predict(np.asarray(input_list).reshape(1, -1))
27
+ # We add '[0]' to the result of the transformed 'res', because 'res' is a list, and we only want
28
+ # the first element.
29
+ # flower_url = "https://raw.githubusercontent.com/featurestoreorg/serverless-ml-course/main/src/01-module/assets/" + res[0] + ".png"
30
+ # img = Image.open(requests.get(flower_url, stream=True).raw)
31
+ # return img
32
+ if (res[0] == 0):
33
+ result = "I'm sorry, the person is dead"
34
+ else:
35
+ result = "Awesome, the person is survived!!!!!!"
36
+ return result
37
+
38
+
39
+ demo = gr.Interface(
40
+ fn=titanic,
41
+ title="Titanic Predictive Analytics",
42
+ description="Experiment with Passenger class/Sex/Age/SibSp to predict if the person is survived or not.",
43
+ allow_flagging="never",
44
+ inputs=[
45
+ gr.inputs.Number(default=1.0, label="Pclass (Flight class 1/2/3)"),
46
+ gr.inputs.Number(default=1.0, label="Sex (male=1/female=2)"),
47
+ gr.inputs.Number(default=1.0, label="Age (in years)"),
48
+ gr.inputs.Number(default=1.0, label="SibSp (number of siblings)"),
49
+ ],
50
+ outputs=gr.Textbox(label="Result: "))
51
 
52
  demo.launch()
53
+