Update app.py
Browse files
app.py
CHANGED
|
@@ -16,24 +16,11 @@ import matplotlib
|
|
| 16 |
matplotlib.use("Agg")
|
| 17 |
import matplotlib.pyplot as plt
|
| 18 |
from matplotlib.ticker import FuncFormatter
|
|
|
|
| 19 |
|
| 20 |
import plotly.graph_objects as go
|
| 21 |
from sklearn.metrics import mean_squared_error
|
| 22 |
|
| 23 |
-
repo_id = "Smart-Thinking/minstress_model"
|
| 24 |
-
model_file = "minstress_model/minstress_model.joblib"
|
| 25 |
-
meta_file = "minstress_model/minstress_meta.json"
|
| 26 |
-
token = os.environ.get("AUTH_TOKEN", "") or (
|
| 27 |
-
st.secrets.get("AUTH_TOKEN", "") if hasattr(st, "secrets") else ""
|
| 28 |
-
)
|
| 29 |
-
|
| 30 |
-
model_path = hf_hub_download(repo_id=repo_id, filename=model_file, token=token)
|
| 31 |
-
model = joblib.load(model_path)
|
| 32 |
-
|
| 33 |
-
meta_path = hf_hub_download(repo_id=repo_id, filename=meta_file, token=token)
|
| 34 |
-
with open(meta_path, "r", encoding="utf-8") as f:
|
| 35 |
-
meta = json.load(f)
|
| 36 |
-
|
| 37 |
|
| 38 |
# =========================
|
| 39 |
# App constants / defaults
|
|
@@ -502,10 +489,14 @@ def _hf_token() -> str:
|
|
| 502 |
return os.environ.get("AUTH_TOKEN", "") or (st.secrets.get("AUTH_TOKEN", "") if hasattr(st, "secrets") else "")
|
| 503 |
|
| 504 |
def _model_file() -> str:
|
| 505 |
-
return os.environ.get("MODEL_FILE", "")
|
|
|
|
|
|
|
| 506 |
|
| 507 |
def _meta_file() -> str:
|
| 508 |
-
return os.environ.get("META_FILE", "")
|
|
|
|
|
|
|
| 509 |
|
| 510 |
@st.cache_resource(show_spinner=False)
|
| 511 |
def load_model_from_hub_or_local() -> object:
|
|
|
|
| 16 |
matplotlib.use("Agg")
|
| 17 |
import matplotlib.pyplot as plt
|
| 18 |
from matplotlib.ticker import FuncFormatter
|
| 19 |
+
from huggingface_hub import hf_hub_download
|
| 20 |
|
| 21 |
import plotly.graph_objects as go
|
| 22 |
from sklearn.metrics import mean_squared_error
|
| 23 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 24 |
|
| 25 |
# =========================
|
| 26 |
# App constants / defaults
|
|
|
|
| 489 |
return os.environ.get("AUTH_TOKEN", "") or (st.secrets.get("AUTH_TOKEN", "") if hasattr(st, "secrets") else "")
|
| 490 |
|
| 491 |
def _model_file() -> str:
|
| 492 |
+
return (os.environ.get("MODEL_FILE", "")
|
| 493 |
+
or (st.secrets.get("MODEL_FILE", "") if hasattr(st, "secrets") else "")
|
| 494 |
+
or "minstress_model/minstress_model.joblib")
|
| 495 |
|
| 496 |
def _meta_file() -> str:
|
| 497 |
+
return (os.environ.get("META_FILE", "")
|
| 498 |
+
or (st.secrets.get("META_FILE", "") if hasattr(st, "secrets") else "")
|
| 499 |
+
or "minstress_model/minstress_meta.json")
|
| 500 |
|
| 501 |
@st.cache_resource(show_spinner=False)
|
| 502 |
def load_model_from_hub_or_local() -> object:
|