root commited on
Commit
c28a7a3
·
1 Parent(s): 4df8760
Files changed (2) hide show
  1. Dockerfile +2 -1
  2. hf_sync.py +12 -43
Dockerfile CHANGED
@@ -32,7 +32,7 @@ RUN wget https://github.com/wkhtmltopdf/packaging/releases/download/0.12.6.1-2/w
32
  WORKDIR /app
33
 
34
  COPY requirements.txt .
35
- RUN pip install --no-cache-dir gunicorn eventlet huggingface_hub[cli]
36
  RUN pip install --no-cache-dir -r requirements.txt
37
 
38
  COPY . .
@@ -46,6 +46,7 @@ ENV PATH=/home/user/.local/bin:$PATH
46
 
47
  ENV PORT=7680
48
  ENV PYTHONUNBUFFERED=1
 
49
 
50
  EXPOSE 7680
51
 
 
32
  WORKDIR /app
33
 
34
  COPY requirements.txt .
35
+ RUN pip install --no-cache-dir gunicorn eventlet "huggingface_hub[cli,hf_transfer]"
36
  RUN pip install --no-cache-dir -r requirements.txt
37
 
38
  COPY . .
 
46
 
47
  ENV PORT=7680
48
  ENV PYTHONUNBUFFERED=1
49
+ ENV HF_HUB_ENABLE_HF_TRANSFER=1
50
 
51
  EXPOSE 7680
52
 
hf_sync.py CHANGED
@@ -6,7 +6,7 @@ import json
6
  import time
7
  import hashlib
8
  from datetime import datetime
9
- from huggingface_hub import HfApi, hf_hub_download
10
 
11
  # Configuration
12
  REPO_ID = os.environ.get("DATASET_REPO_ID", "Jaimodiji/Report-Generator-Data")
@@ -192,48 +192,17 @@ def download(revision=None):
192
  with open(LOCK_FILE, 'w') as f:
193
  f.write(str(os.getpid()))
194
  write_status("running", "download", 5, "Preparing initial data sync...")
195
-
196
- temp_dir = os.path.join("/tmp", f"hf_sync_download_{os.getpid()}")
197
- if os.path.exists(temp_dir):
198
- shutil.rmtree(temp_dir)
199
- os.makedirs(temp_dir, exist_ok=True)
200
-
201
- repo_files = api.list_repo_files(repo_id=REPO_ID, repo_type="dataset", revision=revision)
202
- total_files = max(len(repo_files), 1)
203
- write_status("running", "download", 10, "Downloading dataset files...", f"0/{len(repo_files)} files downloaded")
204
-
205
- for index, repo_file in enumerate(repo_files, start=1):
206
- hf_hub_download(
207
- repo_id=REPO_ID,
208
- repo_type="dataset",
209
- filename=repo_file,
210
- local_dir=temp_dir,
211
- token=HF_TOKEN,
212
- revision=revision,
213
- )
214
- progress = 10 + int((index / total_files) * 75)
215
- write_status("running", "download", progress, "Downloading dataset files...", f"{index}/{len(repo_files)} files downloaded")
216
-
217
- write_status("running", "download", 90, "Applying downloaded data locally...")
218
- protected_names = {os.path.basename(STATUS_FILE)}
219
- for entry in os.listdir(DATA_DIR):
220
- if entry in protected_names:
221
- continue
222
- entry_path = os.path.join(DATA_DIR, entry)
223
- if os.path.isdir(entry_path):
224
- shutil.rmtree(entry_path)
225
- else:
226
- os.remove(entry_path)
227
-
228
- for entry in os.listdir(temp_dir):
229
- src = os.path.join(temp_dir, entry)
230
- dst = os.path.join(DATA_DIR, entry)
231
- if os.path.isdir(src):
232
- shutil.copytree(src, dst, dirs_exist_ok=True)
233
- else:
234
- shutil.copy2(src, dst)
235
-
236
- shutil.rmtree(temp_dir, ignore_errors=True)
237
  write_status("completed", "download", 100, "Initial data sync completed.")
238
  print("Download successful.")
239
  except Exception as e:
 
6
  import time
7
  import hashlib
8
  from datetime import datetime
9
+ from huggingface_hub import HfApi, snapshot_download
10
 
11
  # Configuration
12
  REPO_ID = os.environ.get("DATASET_REPO_ID", "Jaimodiji/Report-Generator-Data")
 
192
  with open(LOCK_FILE, 'w') as f:
193
  f.write(str(os.getpid()))
194
  write_status("running", "download", 5, "Preparing initial data sync...")
195
+ write_status("running", "download", 15, "Listing dataset snapshot...", "Fetching repository metadata")
196
+ write_status("running", "download", 35, "Downloading dataset files...", "Parallel download in progress")
197
+ snapshot_download(
198
+ repo_id=REPO_ID,
199
+ repo_type="dataset",
200
+ local_dir=DATA_DIR,
201
+ token=HF_TOKEN,
202
+ revision=revision,
203
+ max_workers=8
204
+ )
205
+ write_status("running", "download", 90, "Finalizing local dataset...", "Verifying downloaded files")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
206
  write_status("completed", "download", 100, "Initial data sync completed.")
207
  print("Download successful.")
208
  except Exception as e: