bupa1018 commited on
Commit
1ef2ed4
·
1 Parent(s): 1aef3d5

Update download_repo_to_huggingface.py

Browse files
Files changed (1) hide show
  1. download_repo_to_huggingface.py +5 -7
download_repo_to_huggingface.py CHANGED
@@ -4,7 +4,7 @@ import io
4
  import json
5
 
6
 
7
- def download_and_upload_kadiAPY_repo_to_huggingfacespace(api_url, project_id, version):
8
  try:
9
  # Construct the URL for the release's zip file
10
  encoded_project_id = urllib.parse.quote(project_id, safe="")
@@ -14,7 +14,7 @@ def download_and_upload_kadiAPY_repo_to_huggingfacespace(api_url, project_id, ve
14
  response = requests.get(url, stream=True)
15
 
16
  if response.status_code == 200:
17
- _extract_and_upload_file(response, api, DATA_DIR, HF_SPACE_NAME)
18
  else:
19
  print(f"Failed to download the release: {response.status_code} - {response.reason}")
20
  print(response.text)
@@ -27,18 +27,16 @@ def download_and_upload_kadiAPY_repo_to_huggingfacespace(api_url, project_id, ve
27
  print(f"An error occurred: {e}")
28
 
29
 
30
- def _extract_and_upload_file(response, api, DATA_DIR, HF_SPACE_NAME):
31
- """Extracts the archive content and uploads the file."""
32
  archive_bytes = io.BytesIO(response.content)
33
  # Extract filename from content-disposition header
34
  content_disposition = response.headers.get("content-disposition")
35
  if content_disposition and "filename=" in content_disposition:
36
  filename = content_disposition.split("filename=")[-1].strip('"')
37
-
38
- # Upload the file
39
  api.upload_file(
40
  path_or_fileobj=archive_bytes,
41
  path_in_repo=f"{DATA_DIR}/{filename}",
42
  repo_id=HF_SPACE_NAME,
43
  repo_type="space"
44
- )
 
4
  import json
5
 
6
 
7
+ def download_gitlab_repo_to_hfspace(api_url, project_id, version):
8
  try:
9
  # Construct the URL for the release's zip file
10
  encoded_project_id = urllib.parse.quote(project_id, safe="")
 
14
  response = requests.get(url, stream=True)
15
 
16
  if response.status_code == 200:
17
+ _upload_file_to_hfspace(response, api, DATA_DIR, HF_SPACE_NAME)
18
  else:
19
  print(f"Failed to download the release: {response.status_code} - {response.reason}")
20
  print(response.text)
 
27
  print(f"An error occurred: {e}")
28
 
29
 
30
+ def _upload_file_to_hfspace(response, api, DATA_DIR, HF_SPACE_NAME):
 
31
  archive_bytes = io.BytesIO(response.content)
32
  # Extract filename from content-disposition header
33
  content_disposition = response.headers.get("content-disposition")
34
  if content_disposition and "filename=" in content_disposition:
35
  filename = content_disposition.split("filename=")[-1].strip('"')
36
+
 
37
  api.upload_file(
38
  path_or_fileobj=archive_bytes,
39
  path_in_repo=f"{DATA_DIR}/{filename}",
40
  repo_id=HF_SPACE_NAME,
41
  repo_type="space"
42
+ )