Spaces:
Sleeping
Sleeping
Update download_repo.py
Browse files- download_repo.py +9 -4
download_repo.py
CHANGED
@@ -14,6 +14,7 @@ def download_gitlab_repo_to_hfspace(api_url, project_id, version, target_folder,
|
|
14 |
# Construct the URL for the release's zip file
|
15 |
encoded_project_id = urllib.parse.quote(project_id, safe="")
|
16 |
url = f"{api_url}/projects/{encoded_project_id}/repository/archive.zip?sha={version}"
|
|
|
17 |
|
18 |
logging.info(f"Constructed URL: {url}")
|
19 |
|
@@ -23,8 +24,10 @@ def download_gitlab_repo_to_hfspace(api_url, project_id, version, target_folder,
|
|
23 |
|
24 |
if response.status_code == 200:
|
25 |
content_disposition = response.headers.get('content-disposition')
|
|
|
26 |
if content_disposition:
|
27 |
filename = content_disposition.split('filename=')[-1].strip('\"')
|
|
|
28 |
else:
|
29 |
filename = 'archive.zip' # Fallback to a default name if not found
|
30 |
|
@@ -35,6 +38,7 @@ def download_gitlab_repo_to_hfspace(api_url, project_id, version, target_folder,
|
|
35 |
|
36 |
existing_files = hf_api.list_repo_files(repo_id=hf_space_name, repo_type='space')
|
37 |
target_path = f"{target_folder}/{filename}"
|
|
|
38 |
|
39 |
logging.info(f"Target Path: '{target_path}'")
|
40 |
logging.info(f"Existing Files: {[repr(file) for file in existing_files]}")
|
@@ -43,7 +47,9 @@ def download_gitlab_repo_to_hfspace(api_url, project_id, version, target_folder,
|
|
43 |
logging.warning(f"File '{target_path}' already exists in the repository. Skipping upload...")
|
44 |
print(f"File '{target_path}' already exists in the repository. Skipping upload...")
|
45 |
else:
|
46 |
-
|
|
|
|
|
47 |
|
48 |
except FileNotFoundError:
|
49 |
logging.error("The config.json file was not found. Please ensure it exists in the project directory.")
|
@@ -55,12 +61,11 @@ def download_gitlab_repo_to_hfspace(api_url, project_id, version, target_folder,
|
|
55 |
logging.error(f"An unexpected error occurred: {e}")
|
56 |
print(f"An unexpected error occurred: {e}")
|
57 |
|
58 |
-
def _upload_file_to_hfspace(
|
59 |
try:
|
60 |
-
archive_bytes = io.BytesIO(response.content)
|
61 |
logging.info(f"Preparing to upload file to '{target_path}'")
|
62 |
hf_api.upload_file(
|
63 |
-
path_or_fileobj=
|
64 |
path_in_repo=target_path,
|
65 |
repo_id=hf_space_name,
|
66 |
repo_type="space"
|
|
|
14 |
# Construct the URL for the release's zip file
|
15 |
encoded_project_id = urllib.parse.quote(project_id, safe="")
|
16 |
url = f"{api_url}/projects/{encoded_project_id}/repository/archive.zip?sha={version}"
|
17 |
+
print("URL: ", url)
|
18 |
|
19 |
logging.info(f"Constructed URL: {url}")
|
20 |
|
|
|
24 |
|
25 |
if response.status_code == 200:
|
26 |
content_disposition = response.headers.get('content-disposition')
|
27 |
+
print("Content_disposition:", content_disposition)
|
28 |
if content_disposition:
|
29 |
filename = content_disposition.split('filename=')[-1].strip('\"')
|
30 |
+
print("FILENAME: ", filename)
|
31 |
else:
|
32 |
filename = 'archive.zip' # Fallback to a default name if not found
|
33 |
|
|
|
38 |
|
39 |
existing_files = hf_api.list_repo_files(repo_id=hf_space_name, repo_type='space')
|
40 |
target_path = f"{target_folder}/{filename}"
|
41 |
+
print("TARGET PATH: ", target_path)
|
42 |
|
43 |
logging.info(f"Target Path: '{target_path}'")
|
44 |
logging.info(f"Existing Files: {[repr(file) for file in existing_files]}")
|
|
|
47 |
logging.warning(f"File '{target_path}' already exists in the repository. Skipping upload...")
|
48 |
print(f"File '{target_path}' already exists in the repository. Skipping upload...")
|
49 |
else:
|
50 |
+
repo_content= io.BytesIO(response.content)
|
51 |
+
print(repo_content)
|
52 |
+
_upload_file_to_hfspace(repo_content, hf_api, target_path, hf_space_name)
|
53 |
|
54 |
except FileNotFoundError:
|
55 |
logging.error("The config.json file was not found. Please ensure it exists in the project directory.")
|
|
|
61 |
logging.error(f"An unexpected error occurred: {e}")
|
62 |
print(f"An unexpected error occurred: {e}")
|
63 |
|
64 |
+
def _upload_file_to_hfspace(content, hf_api, target_path, hf_space_name):
|
65 |
try:
|
|
|
66 |
logging.info(f"Preparing to upload file to '{target_path}'")
|
67 |
hf_api.upload_file(
|
68 |
+
path_or_fileobj=content,
|
69 |
path_in_repo=target_path,
|
70 |
repo_id=hf_space_name,
|
71 |
repo_type="space"
|