Spaces:
Runtime error
Runtime error
extracting zipped file
Browse files
utils.py
CHANGED
@@ -1,5 +1,8 @@
|
|
1 |
import gdown
|
2 |
from typing import Optional
|
|
|
|
|
|
|
3 |
|
4 |
def download_from_google_drive(file_id: str, destination: Optional[str] = None) -> None:
|
5 |
"""
|
@@ -12,8 +15,28 @@ def download_from_google_drive(file_id: str, destination: Optional[str] = None)
|
|
12 |
output = destination if destination else f"{file_id}.file"
|
13 |
gdown.download(url, output, quiet=False)
|
14 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
15 |
|
16 |
if __name__ == '__main__':
|
17 |
# Example usage
|
18 |
file_id = os.getenv(gdown_file_id) # Replace with your file ID
|
19 |
download_from_google_drive(file_id)
|
|
|
|
|
|
|
|
1 |
import gdown
|
2 |
from typing import Optional
|
3 |
+
import zipfile
|
4 |
+
import os
|
5 |
+
|
6 |
|
7 |
def download_from_google_drive(file_id: str, destination: Optional[str] = None) -> None:
|
8 |
"""
|
|
|
15 |
output = destination if destination else f"{file_id}.file"
|
16 |
gdown.download(url, output, quiet=False)
|
17 |
|
18 |
+
def unzip_file(zip_path: str, extract_to: Optional[str] = None) -> None:
|
19 |
+
"""
|
20 |
+
Unzip a ZIP file to a specified directory.
|
21 |
+
|
22 |
+
:param zip_path: The path to the ZIP file.
|
23 |
+
:param extract_to: The directory to extract the files. If None, extracts to the same directory as the ZIP file.
|
24 |
+
"""
|
25 |
+
if extract_to is None:
|
26 |
+
extract_to = os.path.dirname(zip_path)
|
27 |
+
|
28 |
+
# Ensure the extraction directory exists
|
29 |
+
os.makedirs(extract_to, exist_ok=True)
|
30 |
+
|
31 |
+
with zipfile.ZipFile(zip_path, 'r') as zip_ref:
|
32 |
+
zip_ref.extractall(extract_to)
|
33 |
+
print(f"Files extracted to {extract_to}")
|
34 |
+
|
35 |
|
36 |
if __name__ == '__main__':
|
37 |
# Example usage
|
38 |
file_id = os.getenv(gdown_file_id) # Replace with your file ID
|
39 |
download_from_google_drive(file_id)
|
40 |
+
zip_file_path = "/content/chroma_db-complete.zip" # Replace with your zip file path
|
41 |
+
extract_path = "/chroma_db-complete"
|
42 |
+
unzip_file(zip_file_path,extract_path)
|