howlbz commited on
Commit
5a8af87
1 Parent(s): 25243ca

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +23 -5
app.py CHANGED
@@ -2,7 +2,6 @@ import gradio as gr
2
  import numpy as np
3
  from PIL import Image
4
  import requests
5
- from functions import decode_features, get_model
6
  import hopsworks
7
  import joblib
8
 
@@ -13,10 +12,29 @@ fs = project.get_feature_store()
13
  # model = mr.get_model("xgboost_model", version=1)
14
  # model_dir = model.download()
15
  # model = joblib.load("/model.pkl")
16
- model = get_model(project=project,
17
- model_name="xgboost_model",
18
- evaluation_metric="f1_score",
19
- sort_metrics_by="max")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
20
 
21
  def forecast():
22
 
 
2
  import numpy as np
3
  from PIL import Image
4
  import requests
 
5
  import hopsworks
6
  import joblib
7
 
 
12
  # model = mr.get_model("xgboost_model", version=1)
13
  # model_dir = model.download()
14
  # model = joblib.load("/model.pkl")
15
+
16
+
17
+ def get_model(project, model_name):
18
+ """Retrieve desired model or download it from the Hopsworks Model Registry.
19
+ In second case, it will be physically downloaded to this directory"""
20
+
21
+ TARGET_FILE = "model.pkl"
22
+ list_of_files = [os.path.join(dirpath,filename) for dirpath, _, filenames \
23
+ in os.walk('.') for filename in filenames if filename == TARGET_FILE]
24
+
25
+ if list_of_files:
26
+ model_path = list_of_files[0]
27
+ model = joblib.load(model_path)
28
+ else:
29
+ if not os.path.exists(TARGET_FILE):
30
+ mr = project.get_model_registry()
31
+ model = mr.get_model("xgboost_model", version=1)
32
+ model_dir = model.download()
33
+ model = joblib.load("/model.pkl")
34
+
35
+ return model
36
+
37
+ model = get_model(project,"xgboost_model")
38
 
39
  def forecast():
40