Update app.py
Browse files
app.py
CHANGED
|
@@ -2,27 +2,26 @@ import streamlit as st
|
|
| 2 |
import pandas as pd
|
| 3 |
import json
|
| 4 |
import joblib
|
| 5 |
-
import
|
| 6 |
-
from io import BytesIO
|
| 7 |
-
from zipfile import ZipFile
|
| 8 |
|
| 9 |
# Display the version of huggingface_hub
|
| 10 |
import huggingface_hub
|
| 11 |
st.write(f"Hugging Face Hub version: {huggingface_hub.__version__}")
|
| 12 |
|
| 13 |
-
# Function to download models from Hugging Face using
|
| 14 |
def download_model_from_huggingface(repo_id, filename):
|
| 15 |
"""Downloads a model file from Hugging Face repository."""
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
return
|
| 20 |
-
|
| 21 |
-
|
|
|
|
| 22 |
|
| 23 |
# Function to load models safely
|
| 24 |
def load_model(model_file):
|
| 25 |
-
"""Loads a model from a
|
| 26 |
try:
|
| 27 |
# Here we're assuming the model is in a `.joblib` file format
|
| 28 |
return joblib.load(model_file)
|
|
|
|
| 2 |
import pandas as pd
|
| 3 |
import json
|
| 4 |
import joblib
|
| 5 |
+
from huggingface_hub import hf_hub_download
|
|
|
|
|
|
|
| 6 |
|
| 7 |
# Display the version of huggingface_hub
|
| 8 |
import huggingface_hub
|
| 9 |
st.write(f"Hugging Face Hub version: {huggingface_hub.__version__}")
|
| 10 |
|
| 11 |
+
# Function to download models from Hugging Face using huggingface_hub
|
| 12 |
def download_model_from_huggingface(repo_id, filename):
|
| 13 |
"""Downloads a model file from Hugging Face repository."""
|
| 14 |
+
try:
|
| 15 |
+
# Using huggingface_hub API to download model directly
|
| 16 |
+
model_file = hf_hub_download(repo_id, filename)
|
| 17 |
+
return model_file
|
| 18 |
+
except Exception as e:
|
| 19 |
+
st.error(f"Error downloading model {filename}: {e}")
|
| 20 |
+
return None
|
| 21 |
|
| 22 |
# Function to load models safely
|
| 23 |
def load_model(model_file):
|
| 24 |
+
"""Loads a model from a file."""
|
| 25 |
try:
|
| 26 |
# Here we're assuming the model is in a `.joblib` file format
|
| 27 |
return joblib.load(model_file)
|