Spaces:
Sleeping
Sleeping
updating app.py to retrieve model from HF model folder
Browse files
app.py
CHANGED
|
@@ -8,24 +8,35 @@ from pytrends.request import TrendReq
|
|
| 8 |
import joblib
|
| 9 |
import gradio as gr
|
| 10 |
from sklearn.preprocessing import StandardScaler
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
#
|
| 15 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 16 |
xgb_model = xgb_artifact["model"]
|
| 17 |
xgb_features = xgb_artifact["feature_names"]
|
| 18 |
-
|
| 19 |
-
ngb_artifact =
|
| 20 |
ngb_model = ngb_artifact["model"]
|
| 21 |
ngb_features = ngb_artifact["feature_names"]
|
| 22 |
-
|
| 23 |
-
forecast_ngb_artifact = joblib.load("
|
| 24 |
forecast_ngb_model = forecast_ngb_artifact["model"]
|
| 25 |
forecast_ngb_features = forecast_ngb_artifact["feature_names"]
|
| 26 |
|
| 27 |
# Load KMeans + scaler
|
| 28 |
-
kmeans_artifact =
|
| 29 |
kmeans_model = kmeans_artifact["model"]
|
| 30 |
cluster_scaler = kmeans_artifact["scaler"]
|
| 31 |
# Only use the features that were actually used during training
|
|
@@ -156,8 +167,6 @@ def predict_volatility(date):
|
|
| 156 |
|
| 157 |
|
| 158 |
################### GRADIO INTERFACE
|
| 159 |
-
import gradio as gr
|
| 160 |
-
import pandas as pd
|
| 161 |
|
| 162 |
################### HELPER FUNCTION TO RETURN TABLE ###################
|
| 163 |
def predict_volatility_for_table(date):
|
|
|
|
| 8 |
import joblib
|
| 9 |
import gradio as gr
|
| 10 |
from sklearn.preprocessing import StandardScaler
|
| 11 |
+
from huggingface_hub import hf_hub_download
|
| 12 |
+
|
| 13 |
+
|
| 14 |
+
################### MODEL LOADING FROM HF MODEL REPO
|
| 15 |
+
#define HF's repo path
|
| 16 |
+
HF_repo_id = "Lullooo/BTC-volatility-forecasting-model"
|
| 17 |
+
#define a function to load models from HF
|
| 18 |
+
def load_artifact(filename):
|
| 19 |
+
file_path = hf_hub_download(
|
| 20 |
+
repo_id=HF_repo_id,
|
| 21 |
+
filename=filename,
|
| 22 |
+
repo_type="model"
|
| 23 |
+
)
|
| 24 |
+
return joblib.load(file_path)
|
| 25 |
+
# Load XGBoost
|
| 26 |
+
xgb_artifact = load_artifact("xgb_volatility_model_updated.joblib")
|
| 27 |
xgb_model = xgb_artifact["model"]
|
| 28 |
xgb_features = xgb_artifact["feature_names"]
|
| 29 |
+
# nowcasting NGBoost
|
| 30 |
+
ngb_artifact = load_artifact("ngb_volatility_model_updated.joblib")
|
| 31 |
ngb_model = ngb_artifact["model"]
|
| 32 |
ngb_features = ngb_artifact["feature_names"]
|
| 33 |
+
# forecasting NGboost
|
| 34 |
+
forecast_ngb_artifact = joblib.load("Forecast_ngb_volatility_model_updated.joblib")
|
| 35 |
forecast_ngb_model = forecast_ngb_artifact["model"]
|
| 36 |
forecast_ngb_features = forecast_ngb_artifact["feature_names"]
|
| 37 |
|
| 38 |
# Load KMeans + scaler
|
| 39 |
+
kmeans_artifact = load_artifact("kmeans_model_updated.joblib")
|
| 40 |
kmeans_model = kmeans_artifact["model"]
|
| 41 |
cluster_scaler = kmeans_artifact["scaler"]
|
| 42 |
# Only use the features that were actually used during training
|
|
|
|
| 167 |
|
| 168 |
|
| 169 |
################### GRADIO INTERFACE
|
|
|
|
|
|
|
| 170 |
|
| 171 |
################### HELPER FUNCTION TO RETURN TABLE ###################
|
| 172 |
def predict_volatility_for_table(date):
|