Spaces:
Sleeping
Sleeping
Update app.py (#22)
Browse files- Update app.py (83aab9ce5f70ba14546ed34129cc33b6d022d0b0)
app.py
CHANGED
@@ -50,32 +50,33 @@ def upload_to_huggingface(repo_id, folder_path, oauth_token: Union[gr.OAuthToken
|
|
50 |
return f"Upload failed: {str(e)}"
|
51 |
|
52 |
def process_image_tag(image_tag, repo_id, oauth_token: Union[gr.OAuthToken, None]):
|
53 |
-
# Extract image and tag from the input
|
54 |
-
image, tag = image_tag.split(':')
|
55 |
-
|
56 |
-
# Fetch the manifest JSON
|
57 |
-
manifest_json = fetch_manifest(image, tag)
|
58 |
-
if not manifest_json or 'errors' in manifest_json:
|
59 |
-
return f"Failed to fetch the manifest for {image}:{tag}"
|
60 |
-
|
61 |
-
# Save the manifest JSON to the blobs folder
|
62 |
-
manifest_file_path = "blobs/manifest"
|
63 |
-
os.makedirs(os.path.dirname(manifest_file_path), exist_ok=True)
|
64 |
-
with open(manifest_file_path, 'w') as f:
|
65 |
-
json.dump(manifest_json, f)
|
66 |
-
|
67 |
-
# Extract the digest values from the JSON
|
68 |
-
digests = [layer['digest'] for layer in manifest_json.get('layers', [])]
|
69 |
-
|
70 |
-
# Download each file
|
71 |
-
for digest in digests:
|
72 |
-
download_file(digest, image)
|
73 |
-
|
74 |
-
# Download the config file
|
75 |
-
config_digest = manifest_json.get('config', {}).get('digest')
|
76 |
-
if config_digest:
|
77 |
-
download_file(config_digest, image)
|
78 |
try:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
79 |
# Upload to Hugging Face Hub
|
80 |
upload_result, repo_path = upload_to_huggingface(repo_id, 'blobs', oauth_token)
|
81 |
|
|
|
50 |
return f"Upload failed: {str(e)}"
|
51 |
|
52 |
def process_image_tag(image_tag, repo_id, oauth_token: Union[gr.OAuthToken, None]):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
53 |
try:
|
54 |
+
# Extract image and tag from the input
|
55 |
+
image, tag = image_tag.split(':')
|
56 |
+
|
57 |
+
# Fetch the manifest JSON
|
58 |
+
manifest_json = fetch_manifest(image, tag)
|
59 |
+
if not manifest_json or 'errors' in manifest_json:
|
60 |
+
return f"Failed to fetch the manifest for {image}:{tag}"
|
61 |
+
|
62 |
+
# Save the manifest JSON to the blobs folder
|
63 |
+
manifest_file_path = "blobs/manifest"
|
64 |
+
os.makedirs(os.path.dirname(manifest_file_path), exist_ok=True)
|
65 |
+
with open(manifest_file_path, 'w') as f:
|
66 |
+
json.dump(manifest_json, f)
|
67 |
+
|
68 |
+
# Extract the digest values from the JSON
|
69 |
+
digests = [layer['digest'] for layer in manifest_json.get('layers', [])]
|
70 |
+
|
71 |
+
# Download each file
|
72 |
+
for digest in digests:
|
73 |
+
download_file(digest, image)
|
74 |
+
|
75 |
+
# Download the config file
|
76 |
+
config_digest = manifest_json.get('config', {}).get('digest')
|
77 |
+
if config_digest:
|
78 |
+
download_file(config_digest, image)
|
79 |
+
|
80 |
# Upload to Hugging Face Hub
|
81 |
upload_result, repo_path = upload_to_huggingface(repo_id, 'blobs', oauth_token)
|
82 |
|