Spaces:
Runtime error
Runtime error
File size: 1,530 Bytes
7c39d08 53f53b5 7c39d08 fdcda20 7c39d08 53f53b5 aa08b5f 53f53b5 7c39d08 3ab8b42 7c39d08 53f53b5 |
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 |
import gdown
from typing import Optional
import zipfile
import os
def download_from_google_drive(file_id: str, destination: Optional[str] = None) -> None:
"""
Download a file from Google Drive using its file ID.
:param file_id: The file ID on Google Drive.
:param destination: The path to save the file. If None, the file will be saved in the current directory with its original name.
"""
url = f'https://drive.google.com/uc?id={file_id}'
output = destination if destination else f"{file_id}.file"
print(output)
gdown.download(url, output, quiet=False)
def unzip_file(zip_path: str, extract_to: Optional[str] = None) -> None:
"""
Unzip a ZIP file to a specified directory.
:param zip_path: The path to the ZIP file.
:param extract_to: The directory to extract the files. If None, extracts to the same directory as the ZIP file.
"""
if extract_to is None:
extract_to = os.path.dirname(zip_path)
# Ensure the extraction directory exists
# os.makedirs(extract_to, exist_ok=True)
with zipfile.ZipFile(zip_path, 'r') as zip_ref:
zip_ref.extractall(extract_to)
print(f"Files extracted to {extract_to}")
if __name__ == '__main__':
# Example usage
file_id = os.getenv(gdown_file_id) # Replace with your file ID
download_from_google_drive(file_id)
zip_file_path = "/content/chroma_db-complete.zip" # Replace with your zip file path
extract_path = "/chroma_db-complete"
unzip_file(zip_file_path,extract_path)
|