Fred808 commited on
Commit
abec798
·
verified ·
1 Parent(s): a6e0644

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +53 -0
app.py ADDED
@@ -0,0 +1,53 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from huggingface_hub import snapshot_download, HfApi
2
+ import os
3
+
4
+ # User's dataset repository ID
5
+ DATASET_REPO_ID = "Fred808/helium_memory"
6
+
7
+ # Model to download
8
+ MODEL_REPO_ID = "bert-base-uncased"
9
+
10
+ # Local directory to save downloaded model data temporarily
11
+ DOWNLOAD_DIR = "./downloaded_model_data"
12
+
13
+ # Hugging Face API Token (provided by user)
14
+ HUGGINGFACE_TOKEN = os.environ.get("HUGGINGFACE_TOKEN")
15
+
16
+ # Ensure the download directory exists
17
+ os.makedirs(DOWNLOAD_DIR, exist_ok=True)
18
+
19
+ def download_full_model(repo_id, download_dir):
20
+ """Downloads an entire model from a Hugging Face model repository."""
21
+ print(f"Downloading full model from {repo_id}...")
22
+ local_dir = snapshot_download(repo_id=repo_id, cache_dir=download_dir)
23
+ print(f"Downloaded to: {local_dir}")
24
+ return local_dir
25
+
26
+ def upload_folder_to_dataset(dataset_repo_id, folder_path, path_in_repo, token):
27
+ """Uploads a folder to a Hugging Face dataset repository."""
28
+ api = HfApi(token=token)
29
+ print(f"Uploading {folder_path} to {dataset_repo_id} at {path_in_repo}...")
30
+ api.upload_folder(
31
+ folder_path=folder_path,
32
+ path_in_repo=path_in_repo,
33
+ repo_id=dataset_repo_id,
34
+ repo_type="dataset",
35
+ )
36
+ print("Upload complete!")
37
+
38
+ if __name__ == "__main__":
39
+ # 1. Download full model data
40
+ downloaded_folder = download_full_model(MODEL_REPO_ID, DOWNLOAD_DIR)
41
+
42
+ # 2. Upload the downloaded data to the user's dataset
43
+ # The path in the dataset will be 'model_data/bert-base-uncased/'
44
+ path_in_dataset = f"model_data/{MODEL_REPO_ID}/"
45
+ upload_folder_to_dataset(DATASET_REPO_ID, downloaded_folder, path_in_dataset, HUGGINGFACE_TOKEN)
46
+
47
+ print("Script finished successfully.")
48
+
49
+
50
+
51
+
52
+ if not HUGGINGFACE_TOKEN:
53
+ raise ValueError("HUGGINGFACE_TOKEN environment variable not set.")