File size: 1,404 Bytes
5d4981c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
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)