reach-vb HF staff commited on
Commit
a2a424f
·
verified ·
1 Parent(s): 206c446

Update app.py (#26)

Browse files

- Update app.py (c22eda8dbeff393998ea7a5771fb822cda465ee3)
- Update app.py (0b8a50cce4668cb4992119e0e9fa210d81703402)

Files changed (1) hide show
  1. app.py +11 -10
app.py CHANGED
@@ -6,9 +6,9 @@ import shutil
6
  from huggingface_hub import HfApi, create_repo
7
  from typing import Union
8
 
9
- def download_file(digest, image):
10
  url = f"https://registry.ollama.ai/v2/library/{image}/blobs/{digest}"
11
- file_name = f"blobs/{digest}"
12
 
13
  # Create the directory if it doesn't exist
14
  os.makedirs(os.path.dirname(file_name), exist_ok=True)
@@ -65,17 +65,18 @@ def process_image_tag(image_tag, repo_id, oauth_token: Union[gr.OAuthToken, None
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)
 
6
  from huggingface_hub import HfApi, create_repo
7
  from typing import Union
8
 
9
+ def download_file(media_type, digest, image):
10
  url = f"https://registry.ollama.ai/v2/library/{image}/blobs/{digest}"
11
+ file_name = f"blobs/{media_type.split(".")[-1]}"
12
 
13
  # Create the directory if it doesn't exist
14
  os.makedirs(os.path.dirname(file_name), exist_ok=True)
 
65
  with open(manifest_file_path, 'w') as f:
66
  json.dump(manifest_json, f)
67
 
68
+ # Extract the mediaType and digest values from the JSON
69
+ layers = manifest_json.get('layers', [])
70
+ for layer in layers:
71
+ media_type = layer['mediaType']
72
+ digest = layer['digest']
73
+ download_file(media_type, digest, image)
74
 
75
  # Download the config file
76
+ config_media_type = manifest_json.get('config', {}).get('mediaType')
77
  config_digest = manifest_json.get('config', {}).get('digest')
78
+ if config_media_type and config_digest:
79
+ download_file(config_media_type, config_digest, image)
80
 
81
  # Upload to Hugging Face Hub
82
  upload_result, repo_path = upload_to_huggingface(repo_id, 'blobs', oauth_token)