soiz1 commited on
Commit
7932dff
·
verified ·
1 Parent(s): ffc7490

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +22 -12
app.py CHANGED
@@ -6,20 +6,30 @@ import gradio as gr
6
 
7
  def download_huggingface_repo(repo_url):
8
  # Extract the repo ID from the URL
9
- repo_id = repo_url.replace("https://huggingface.co/", "").strip()
10
-
11
- output_dir = "repo"
12
- zip_file = "repo.zip"
13
-
14
- # Clean up previous files
15
- if os.path.exists(output_dir):
16
- shutil.rmtree(output_dir)
17
- if os.path.exists(zip_file):
18
- os.remove(zip_file)
19
-
20
  try:
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
21
  # Download the repository using Hugging Face Hub
22
- snapshot_download(repo_id, local_dir=output_dir)
23
 
24
  # Create a zip file of the downloaded repository
25
  with zipfile.ZipFile(zip_file, "w", zipfile.ZIP_DEFLATED) as zipf:
 
6
 
7
  def download_huggingface_repo(repo_url):
8
  # Extract the repo ID from the URL
 
 
 
 
 
 
 
 
 
 
 
9
  try:
10
+ if "huggingface.co/" not in repo_url:
11
+ raise ValueError("Invalid URL: The provided URL does not belong to Hugging Face.")
12
+
13
+ repo_id = repo_url.replace("https://huggingface.co/", "").strip()
14
+
15
+ # Detect repo type (spaces, models, or datasets)
16
+ if repo_id.startswith("spaces/"):
17
+ repo_type = "space"
18
+ repo_id = repo_id.replace("spaces/", "")
19
+ else:
20
+ repo_type = None # Default type (models or datasets)
21
+
22
+ output_dir = "repo"
23
+ zip_file = "repo.zip"
24
+
25
+ # Clean up previous files
26
+ if os.path.exists(output_dir):
27
+ shutil.rmtree(output_dir)
28
+ if os.path.exists(zip_file):
29
+ os.remove(zip_file)
30
+
31
  # Download the repository using Hugging Face Hub
32
+ snapshot_download(repo_id, local_dir=output_dir, repo_type=repo_type)
33
 
34
  # Create a zip file of the downloaded repository
35
  with zipfile.ZipFile(zip_file, "w", zipfile.ZIP_DEFLATED) as zipf: