ads505-app / utils /load_pred_model.py
Taylor Kirk
Fresh deployment after moving datasets to hf datahub
5d4981c
import streamlit as st
from pathlib import Path
import pandas as pd
import joblib
from huggingface_hub import hf_hub_download
# def get_root():
# # app_utils is inside streamlit_app, so parent is streamlit_app
# return Path(__file__).resolve().parent.parent
# # def get_model_path():
# # return get_root() / "models" / "sgdc_pipeline.joblib"
# def get_data_path():
# return get_root() / "models" / "demo_data.parquet"
# @st.cache_resource(show_spinner='Loading model')
# def load_model():
# path = get_model_path()
# if not path.exists():
# raise FileNotFoundError(f"Model file not found at: {path}")
# return joblib.load(path)
@st.cache_resource(show_spinner='Loading model') # Use this so it only downloads once per session
def load_model():
# Download the model file from your new Model Repo
model_path = hf_hub_download(
repo_id="tkbarb10/ads505-prediction-model",
filename="sgdc_pipeline.joblib"
)
# Load the model using joblib (or whatever library you used to save it)
return joblib.load(model_path)
@st.cache_data(show_spinner='Loading demo data...')
def load_demo_data():
# Download the parquet file from your Dataset Repo
file_path = hf_hub_download(
repo_id="tkbarb10/ads505-review-data",
repo_type="dataset",
filename="demo_data.parquet"
)
return pd.read_parquet(file_path)