Spaces:
Sleeping
Sleeping
Update download_repo.py
Browse files- download_repo.py +5 -5
download_repo.py
CHANGED
@@ -9,7 +9,7 @@ import logging
|
|
9 |
# Set up logging
|
10 |
logging.basicConfig(level=logging.ERROR, format='%(asctime)s - %(levelname)s - %(message)s')
|
11 |
|
12 |
-
def download_gitlab_repo_to_hfspace(api_url, project_id, version, target_folder):
|
13 |
try:
|
14 |
# Construct the URL for the release's zip file
|
15 |
encoded_project_id = urllib.parse.quote(project_id, safe="")
|
@@ -33,7 +33,7 @@ def download_gitlab_repo_to_hfspace(api_url, project_id, version, target_folder)
|
|
33 |
logging.error(f"Failed to download the file. HTTP Status: {response.status_code}")
|
34 |
return
|
35 |
|
36 |
-
existing_files =
|
37 |
target_path = f"{target_folder}/{filename}"
|
38 |
|
39 |
logging.info(f"Target Path: '{target_path}'")
|
@@ -43,7 +43,7 @@ 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 |
-
_upload_file_to_hfspace(response,
|
47 |
|
48 |
except FileNotFoundError:
|
49 |
logging.error("The config.json file was not found. Please ensure it exists in the project directory.")
|
@@ -55,11 +55,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(response,
|
59 |
try:
|
60 |
archive_bytes = io.BytesIO(response.content)
|
61 |
logging.info(f"Preparing to upload file to '{target_path}'")
|
62 |
-
|
63 |
path_or_fileobj=archive_bytes,
|
64 |
path_in_repo=target_path,
|
65 |
repo_id=HF_SPACE_NAME,
|
|
|
9 |
# Set up logging
|
10 |
logging.basicConfig(level=logging.ERROR, format='%(asctime)s - %(levelname)s - %(message)s')
|
11 |
|
12 |
+
def download_gitlab_repo_to_hfspace(api_url, project_id, version, target_folder, hf_api):
|
13 |
try:
|
14 |
# Construct the URL for the release's zip file
|
15 |
encoded_project_id = urllib.parse.quote(project_id, safe="")
|
|
|
33 |
logging.error(f"Failed to download the file. HTTP Status: {response.status_code}")
|
34 |
return
|
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}'")
|
|
|
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 |
+
_upload_file_to_hfspace(response, hf_api, target_path, HF_SPACE_NAME)
|
47 |
|
48 |
except FileNotFoundError:
|
49 |
logging.error("The config.json file was not found. Please ensure it exists in the project directory.")
|
|
|
55 |
logging.error(f"An unexpected error occurred: {e}")
|
56 |
print(f"An unexpected error occurred: {e}")
|
57 |
|
58 |
+
def _upload_file_to_hfspace(response, hf_api, target_path, HF_SPACE_NAME):
|
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=archive_bytes,
|
64 |
path_in_repo=target_path,
|
65 |
repo_id=HF_SPACE_NAME,
|