Duskfallcrew commited on
Commit
d4bcc30
·
verified ·
1 Parent(s): 3e84455

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -19
app.py CHANGED
@@ -58,13 +58,7 @@ def create_model_repo(api, user, orgs_name, model_name, make_private=False):
58
 
59
  # ---------------------- MODEL LOADING AND CONVERSION ----------------------
60
  def download_model(model_path_or_url):
61
- """Downloads a model from a URL or Hugging Face Hub, handling various cases.
62
- Args:
63
- model_path_or_url: Can be a local path, a URL, a Hugging Face repo ID,
64
- or a repo ID with a filename (e.g., "user/repo/file.safetensors").
65
- Returns:
66
- The local path to the downloaded (or existing) file.
67
- """
68
  try:
69
  # Check if it's a valid Hugging Face repo ID (and potentially a file within)
70
  try:
@@ -73,30 +67,29 @@ def download_model(model_path_or_url):
73
  local_path = hf_hub_download(repo_id=model_path_or_url)
74
  return local_path
75
  except HFValidationError:
76
- # Not a simple repo ID. Might be a repo ID with a filename, or a URL.
77
- pass
78
 
79
  if model_path_or_url.startswith("http://") or model_path_or_url.startswith("https://"):
80
- # It's a URL, use hf_hub_download to handle it (it handles URLs gracefully).
81
- local_path = hf_hub_download(repo_id=None, filename=None, repo_type=None, url=model_path_or_url)
82
  return local_path
83
- elif os.path.isfile(model_path_or_url): # Local File
 
84
  return model_path_or_url
85
- else: #HuggingFace Model
86
- # Try splitting into repo ID and filename (for "user/repo/file.safetensors")
87
  try:
88
- parts = model_path_or_url.split("/", 1) # Split only on the first /
89
  if len(parts) == 2:
90
  repo_id, filename = parts
91
- validate_repo_id(repo_id) # Check the repo_id part.
92
  local_path = hf_hub_download(repo_id=repo_id, filename=filename)
93
  return local_path
94
  else:
95
- raise ValueError("Invalid input")
96
- except HFValidationError: #Still invalid
97
  raise ValueError(f"Invalid model path or URL: {model_path_or_url}")
98
 
99
-
100
  except Exception as e:
101
  raise ValueError(f"Error downloading or accessing model: {e}")
102
 
 
58
 
59
  # ---------------------- MODEL LOADING AND CONVERSION ----------------------
60
  def download_model(model_path_or_url):
61
+ """Downloads a model, handling URLs, HF repos, and local paths."""
 
 
 
 
 
 
62
  try:
63
  # Check if it's a valid Hugging Face repo ID (and potentially a file within)
64
  try:
 
67
  local_path = hf_hub_download(repo_id=model_path_or_url)
68
  return local_path
69
  except HFValidationError:
70
+ pass # Not a simple repo ID. Might be repo ID + filename, or a URL.
 
71
 
72
  if model_path_or_url.startswith("http://") or model_path_or_url.startswith("https://"):
73
+ # It's a URL: use hf_hub_download with the url parameter
74
+ local_path = hf_hub_download(url=model_path_or_url) # Corrected line
75
  return local_path
76
+ elif os.path.isfile(model_path_or_url):
77
+ # It's a local file
78
  return model_path_or_url
79
+ else:
80
+ # Try splitting into repo ID and filename
81
  try:
82
+ parts = model_path_or_url.split("/", 1)
83
  if len(parts) == 2:
84
  repo_id, filename = parts
85
+ validate_repo_id(repo_id)
86
  local_path = hf_hub_download(repo_id=repo_id, filename=filename)
87
  return local_path
88
  else:
89
+ raise ValueError("Invalid input format")
90
+ except HFValidationError:
91
  raise ValueError(f"Invalid model path or URL: {model_path_or_url}")
92
 
 
93
  except Exception as e:
94
  raise ValueError(f"Error downloading or accessing model: {e}")
95