File size: 4,258 Bytes
352b049
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
import os
from huggingface_hub import hf_hub_download, list_repo_files
import tarfile
import shutil
from tqdm import tqdm

def download_and_extract_file(repo_id, filename, local_dir):
    """
    Download and extract a file from Hugging Face.
    
    Args:
        repo_id (str): The repository ID on Hugging Face
        filename (str): The name of the file to download
        local_dir (str): The directory to extract files to
    """
    print(f"Starting download of {filename}...")
    
    # Create directory if it doesn't exist
    os.makedirs(local_dir, exist_ok=True)
    
    try:
        # Download the file using hf_hub_download
        file_path = hf_hub_download(
            repo_id=repo_id,
            filename=filename,
            repo_type="space",
            local_dir=local_dir
        )
        
        print(f"Download completed. File saved to: {file_path}")
        
        # Extract the tar.xz file with progress bar
        print(f"Extracting {filename}...")
        with tarfile.open(file_path, 'r:xz') as tar:
            # Get total number of files
            total_files = len(tar.getmembers())
            
            # Extract with progress bar
            for member in tqdm(tar.getmembers(), total=total_files, desc=f"Extracting {filename}"):
                tar.extract(member, path=local_dir)
        
        print(f"Extraction of {filename} completed successfully!")
        
        # Clean up the downloaded archive
        os.remove(file_path)
        print(f"Cleaned up downloaded archive {filename}.")
        
    except Exception as e:
        print(f"An error occurred while processing {filename}: {str(e)}")
        # Clean up in case of error
        if os.path.exists(file_path):
            os.remove(file_path)
        raise

def download_video_files(repo_id, local_dir):
    """
    Download all video files from the downloads directory.
    
    Args:
        repo_id (str): The repository ID on Hugging Face
        local_dir (str): The directory to save videos to
    """
    print("Starting download of video files...")
    
    # Create downloads directory if it doesn't exist
    os.makedirs(local_dir, exist_ok=True)
    
    try:
        # List all files in the downloads directory
        files = list_repo_files(
            repo_id=repo_id,
            repo_type="space",
            revision="main"
        )
        
        # Filter for video files in the downloads directory
        video_files = [f for f in files if f.startswith('downloads/') and f.endswith('.mp4')]
        
        if not video_files:
            print("No video files found in the downloads directory.")
            return
        
        print(f"Found {len(video_files)} video files to download.")
        
        # Download each video file
        for video_file in video_files:
            print(f"\nDownloading {video_file}...")
            hf_hub_download(
                repo_id=repo_id,
                filename=video_file,
                repo_type="space",
                local_dir=local_dir
            )
            print(f"Downloaded {video_file} successfully!")
        
        print("\nAll video files downloaded successfully!")
        
    except Exception as e:
        print(f"An error occurred while downloading video files: {str(e)}")
        raise

def download_and_extract_precomputed():
    """
    Download and extract precomputed results from Hugging Face.
    Downloads both intermediate_results.tar.xz and outputs.tar.xz,
    and downloads all video files from the downloads directory.
    """
    repo_id = "abdullahyang/NonisotropicSkeletonDiffusion_PrecomputedResults"
    
    # Download and extract intermediate_results.tar.xz
    download_and_extract_file(
        repo_id=repo_id,
        filename="intermediate_results.tar.xz",
        local_dir="."
    )
    
    # Download and extract outputs.tar.xz
    download_and_extract_file(
        repo_id=repo_id,
        filename="outputs.tar.xz",
        local_dir="."
    )
    
    # Download video files
    download_video_files(
        repo_id=repo_id,
        local_dir="."
    )
    
    print("All downloads and extractions completed successfully!")

if __name__ == "__main__":
    download_and_extract_precomputed()