File size: 1,045 Bytes
5c6dd58 5064f83 5c6dd58 5064f83 5c6dd58 5064f83 5c6dd58 |
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 |
import os
import joblib
import pandas as pd
import streamlit as st
from dotenv import load_dotenv
from huggingface_hub import hf_hub_download, login
from src.data_loading import create_features
def load_model(particle):
load_dotenv()
login(token=os.getenv("HUGGINGFACE_DOWNLOAD_TOKEN"))
repo_id = f"elisaklunder/Utrecht-{particle}-Forecasting-Model"
if particle == "O3":
file_name = "O3_svr_model.pkl"
elif particle == "NO2":
file_name == "hehehe"
model_path = hf_hub_download(repo_id=repo_id, filename=file_name)
model = joblib.load(model_path)
return model
@st.cache_resource(ttl=6 * 300) # Reruns every 6 hours
def run_model(particle, data):
input_data = create_features(data=data, target_particle=particle)
model = load_model(particle)
# Run the model with static input
prediction = model.predict(input_data)
target_scaler = joblib.load(f"scalers/target_scaler_{particle}.joblib")
prediction = target_scaler.inverse_transform(prediction)
return prediction
|