kk90ujhun commited on
Commit
f75faca
1 Parent(s): 856065b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -44
app.py CHANGED
@@ -1,53 +1,22 @@
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
 
13
- mr = project.get_model_registry()
14
- model = mr.get_model("titanic_modal", version=10)
15
- model_dir = model.download()
16
- model = joblib.load(model_dir + "/titanic_model.pkl")
 
 
 
 
17
 
18
- def titanic(age, embarked, fare, parch, pclass, sex, sibsp):
19
- input_list = []
20
- input_list.append(age)
21
- input_list.append(embarked)
22
- input_list.append(fare)
23
- input_list.append(parch)
24
- input_list.append(pclass)
25
- input_list.append(sex)
26
- input_list.append(sibsp)
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 the first element.
30
- # flower_url = "https://raw.githubusercontent.com/featurestoreorg/serverless-ml-course/main/src/01-module/assets/" + res[0] + ".png"
31
- # img = Image.open(requests.get(flower_url, stream=True).raw)
32
- if res == [1]:
33
- res = 'survive'
34
- else:
35
- res = 'die'
36
- return res
37
-
38
- demo = gr.Interface(
39
- fn=titanic,
40
- title="Titanic Survivor Predictive Analytics",
41
- description="Experiment with age/embarked/fare/parch/pclass/sex/sibsp to predict if the passenger survived.",
42
- allow_flagging="never",
43
- inputs=[
44
- gr.inputs.Number(default=2.0, label="age"),
45
- gr.inputs.Number(default=1.0, label="embarked (0 for S, 1 for C, 2 for Q)"),
46
- gr.inputs.Number(default=35.0, label="fare"),
47
- gr.inputs.Number(default=1.0, label="parch"),
48
- gr.inputs.Number(default=1.0, label="pclass"),
49
- gr.inputs.Number(default=1.0, label="sex (0 for male, 1 for male)"),
50
- gr.inputs.Number(default=1.0, label="sibsp")
51
- ],
52
- outputs=gr.Textbox())
53
- demo.launch()
 
1
  import gradio as gr
 
2
  from PIL import Image
 
 
3
  import hopsworks
 
4
 
5
  project = hopsworks.login()
6
  fs = project.get_feature_store()
7
 
8
+ dataset_api = project.get_dataset_api()
9
+
10
+ dataset_api.download("Resources/images/df_recent.png", overwrite=True)
11
+ dataset_api.download("Resources/images/confusion_matrix.png", overwrite=True)
12
 
13
+ with gr.Blocks() as demo:
14
+ with gr.Row():
15
+ with gr.Column():
16
+ gr.Label("Recent Prediction History")
17
+ input_img = gr.Image("df_recent.png", elem_id="recent-predictions")
18
+ with gr.Column():
19
+ gr.Label("Confusion Maxtrix with Historical Prediction Performance")
20
+ input_img = gr.Image("confusion_matrix.png", elem_id="confusion-matrix")
21
 
22
+ demo.launch(share=True)