Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -43,57 +43,47 @@ login(HF_TOKEN)
|
|
43 |
api = HfApi()
|
44 |
|
45 |
|
46 |
-
def load_project_ids(json_file):
|
47 |
-
with open(json_file, 'r') as f:
|
48 |
-
data = json.load(f)
|
49 |
-
return data['project_ids']
|
50 |
-
|
51 |
def download_gitlab_repo():
|
52 |
print("Start the upload_gitRepository function")
|
53 |
-
|
|
|
|
|
|
|
|
|
54 |
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
# Define the URL to download the repository archive
|
59 |
-
archive_url = f"{GITLAB_API_URL}/projects/{encoded_project_id}/repository/archive.zip"
|
60 |
-
|
61 |
-
# Download the repository archive
|
62 |
-
response = requests.get(archive_url)
|
63 |
-
archive_bytes = io.BytesIO(response.content)
|
64 |
-
|
65 |
-
# Retrieve the original file name from the response headers
|
66 |
-
content_disposition = response.headers.get('content-disposition')
|
67 |
-
if content_disposition:
|
68 |
-
filename = content_disposition.split('filename=')[-1].strip('\"')
|
69 |
-
else:
|
70 |
-
filename = 'archive.zip' # Fallback to a default name if not found
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
# Check if the file already exists in the repository
|
75 |
-
existing_files = api.list_repo_files(repo_id=HF_SPACE_NAME, repo_type='space')
|
76 |
-
target_path = f"{REPOSITORY_DIRECTORY}/{filename}"
|
77 |
-
|
78 |
-
print(f"Target Path: '{target_path}'")
|
79 |
-
print(f"Existing Files: {[repr(file) for file in existing_files]}")
|
80 |
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
97 |
|
98 |
|
99 |
def process_directory(directory):
|
|
|
43 |
api = HfApi()
|
44 |
|
45 |
|
|
|
|
|
|
|
|
|
|
|
46 |
def download_gitlab_repo():
|
47 |
print("Start the upload_gitRepository function")
|
48 |
+
project_id = config['project_id']
|
49 |
+
encoded_project_id = urllib.parse.quote_plus(project_id)
|
50 |
+
|
51 |
+
# Define the URL to download the repository archive
|
52 |
+
archive_url = f"{GITLAB_API_URL}/projects/{encoded_project_id}/repository/archive.zip"
|
53 |
|
54 |
+
# Download the repository archive
|
55 |
+
response = requests.get(archive_url)
|
56 |
+
archive_bytes = io.BytesIO(response.content)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
57 |
|
58 |
+
# Retrieve the original file name from the response headers
|
59 |
+
content_disposition = response.headers.get('content-disposition')
|
60 |
+
if content_disposition:
|
61 |
+
filename = content_disposition.split('filename=')[-1].strip('\"')
|
62 |
+
else:
|
63 |
+
filename = 'archive.zip' # Fallback to a default name if not found
|
64 |
+
|
65 |
+
# Check if the file already exists in the repository
|
66 |
+
existing_files = api.list_repo_files(repo_id=HF_SPACE_NAME, repo_type='space')
|
67 |
+
target_path = f"{REPOSITORY_DIRECTORY}/{filename}"
|
68 |
+
|
69 |
+
print(f"Target Path: '{target_path}'")
|
70 |
+
print(f"Existing Files: {[repr(file) for file in existing_files]}")
|
71 |
+
|
72 |
+
if target_path in existing_files:
|
73 |
+
print(f"File '{target_path}' already exists in the repository. Skipping upload...")
|
74 |
+
else:
|
75 |
+
# Upload the ZIP file to the new folder in the Hugging Face space repository
|
76 |
+
print("Uploading File to directory:")
|
77 |
+
print(f"Archive Bytes: {repr(archive_bytes.getvalue())[:100]}") # Show a preview of bytes
|
78 |
+
print(f"Target Path in Repo: '{target_path}'")
|
79 |
+
|
80 |
+
api.upload_file(
|
81 |
+
path_or_fileobj=archive_bytes,
|
82 |
+
path_in_repo=target_path,
|
83 |
+
repo_id=HF_SPACE_NAME,
|
84 |
+
repo_type='space'
|
85 |
+
)
|
86 |
+
print("Upload complete")
|
87 |
|
88 |
|
89 |
def process_directory(directory):
|