reach-vb HF staff commited on
Commit
f1eb3e2
·
verified ·
1 Parent(s): 12cb0d4

Update app.py (#13)

Browse files

- Update app.py (117597ab20fab226e8cff281516e6bf87c9e1c7e)

Files changed (1) hide show
  1. app.py +26 -25
app.py CHANGED
@@ -47,40 +47,41 @@ def upload_to_huggingface(repo_id, folder_path, oauth_token: Union[gr.OAuthToken
47
 
48
  def process_image_tag(image_tag, repo_id, oauth_token: Union[gr.OAuthToken, None]):
49
  # Extract image and tag from the input
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
50
  try:
51
- image, tag = image_tag.split(':')
52
-
53
- # Fetch the manifest JSON
54
- manifest_json = fetch_manifest(image, tag)
55
- if not manifest_json or 'errors' in manifest_json:
56
- return f"Failed to fetch the manifest for {image}:{tag}"
57
-
58
- # Save the manifest JSON to the blobs folder
59
- manifest_file_path = "blobs/manifest.json"
60
- os.makedirs(os.path.dirname(manifest_file_path), exist_ok=True)
61
- with open(manifest_file_path, 'w') as f:
62
- json.dump(manifest_json, f)
63
-
64
- # Extract the digest values from the JSON
65
- digests = [layer['digest'] for layer in manifest_json.get('layers', [])]
66
-
67
- # Download each file
68
- for digest in digests:
69
- download_file(digest, image)
70
-
71
- # Download the config file
72
- config_digest = manifest_json.get('config', {}).get('digest')
73
- if config_digest:
74
- download_file(config_digest, image)
75
-
76
  # Upload to Hugging Face Hub
77
  upload_result = upload_to_huggingface(repo_id, 'blobs/*', oauth_token)
78
 
79
  # Delete the blobs folder
80
  shutil.rmtree('blobs')
 
81
  return f"Successfully fetched and downloaded files for {image}:{tag}\n{upload_result}\nBlobs folder deleted"
82
  except Exception as e:
83
  shutil.rmtree('blobs', ignore_errors=True)
 
84
  return f"Error found: {str(e)}"
85
 
86
  css = """
 
47
 
48
  def process_image_tag(image_tag, repo_id, oauth_token: Union[gr.OAuthToken, None]):
49
  # Extract image and tag from the input
50
+ image, tag = image_tag.split(':')
51
+
52
+ # Fetch the manifest JSON
53
+ manifest_json = fetch_manifest(image, tag)
54
+ if not manifest_json or 'errors' in manifest_json:
55
+ return f"Failed to fetch the manifest for {image}:{tag}"
56
+
57
+ # Save the manifest JSON to the blobs folder
58
+ manifest_file_path = "blobs/manifest.json"
59
+ os.makedirs(os.path.dirname(manifest_file_path), exist_ok=True)
60
+ with open(manifest_file_path, 'w') as f:
61
+ json.dump(manifest_json, f)
62
+
63
+ # Extract the digest values from the JSON
64
+ digests = [layer['digest'] for layer in manifest_json.get('layers', [])]
65
+
66
+ # Download each file
67
+ for digest in digests:
68
+ download_file(digest, image)
69
+
70
+ # Download the config file
71
+ config_digest = manifest_json.get('config', {}).get('digest')
72
+ if config_digest:
73
+ download_file(config_digest, image)
74
  try:
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
75
  # Upload to Hugging Face Hub
76
  upload_result = upload_to_huggingface(repo_id, 'blobs/*', oauth_token)
77
 
78
  # Delete the blobs folder
79
  shutil.rmtree('blobs')
80
+
81
  return f"Successfully fetched and downloaded files for {image}:{tag}\n{upload_result}\nBlobs folder deleted"
82
  except Exception as e:
83
  shutil.rmtree('blobs', ignore_errors=True)
84
+
85
  return f"Error found: {str(e)}"
86
 
87
  css = """