jmhb commited on
Commit
58819bb
·
verified ·
1 Parent(s): 33c86ef

Create download_data.py

Browse files
Files changed (1) hide show
  1. data/download_data.py +36 -0
data/download_data.py ADDED
@@ -0,0 +1,36 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from huggingface_hub import hf_hub_download
2
+ import zipfile
3
+ import os
4
+
5
+ def download_and_extract_videos(dataset_name, output_dir, domain):
6
+ # Create output directory if it doesn't exist
7
+ os.makedirs(output_dir, exist_ok=True)
8
+
9
+ # Download the zip file
10
+ # print(f"Downloading {zip_filename} from the dataset...")
11
+ zip_path = hf_hub_download(
12
+ repo_id=dataset_name,
13
+ filename=f"data/videos_{domain}.zip",
14
+ repo_type="dataset",
15
+ local_dir=output_dir,
16
+ )
17
+
18
+ # Extract the zip file
19
+ with zipfile.ZipFile(zip_path, 'r') as zip_ref:
20
+ for file_info in zip_ref.infolist():
21
+ extracted_path = os.path.join(output_dir, file_info.filename)
22
+ if file_info.filename.endswith('/'):
23
+ os.makedirs(extracted_path, exist_ok=True)
24
+ else:
25
+ os.makedirs(os.path.dirname(extracted_path), exist_ok=True)
26
+ with zip_ref.open(file_info) as source, open(extracted_path, "wb") as target:
27
+ target.write(source.read())
28
+
29
+ print(f"Videos extracted to {output_dir}")
30
+
31
+ # Usage
32
+ dataset_name = "viddiff/viddiff"
33
+ output_dir = "."
34
+ domains = ("surgery", "fitness")
35
+ for domain in domains:
36
+ download_and_extract_videos(dataset_name, output_dir, domain)