totoro74 commited on
Commit
7b58ffd
·
verified ·
1 Parent(s): 5105548

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -11
app.py CHANGED
@@ -2,27 +2,26 @@ import streamlit as st
2
  import pandas as pd
3
  import json
4
  import joblib
5
- import requests
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 requests
14
  def download_model_from_huggingface(repo_id, filename):
15
  """Downloads a model file from Hugging Face repository."""
16
- url = f"https://huggingface.co/{repo_id}/resolve/main/{filename}"
17
- response = requests.get(url)
18
- if response.status_code == 200:
19
- return BytesIO(response.content)
20
- else:
21
- raise Exception(f"Failed to download {filename}")
 
22
 
23
  # Function to load models safely
24
  def load_model(model_file):
25
- """Loads a model from a BytesIO object."""
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)