Spaces:
Running
Running
Upload utils.py
Browse files
utils.py
CHANGED
|
@@ -121,9 +121,17 @@ def download_and_unzip_gdrive_folder(folder_id_or_url: str, target_dir_for_conte
|
|
| 121 |
if not os.path.exists(target_dir_for_contents):
|
| 122 |
os.makedirs(target_dir_for_contents)
|
| 123 |
|
|
|
|
| 124 |
src_root = temp_dir
|
| 125 |
-
|
| 126 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 127 |
|
| 128 |
for item in os.listdir(src_root):
|
| 129 |
shutil.move(os.path.join(src_root, item), os.path.join(target_dir_for_contents, item))
|
|
|
|
| 121 |
if not os.path.exists(target_dir_for_contents):
|
| 122 |
os.makedirs(target_dir_for_contents)
|
| 123 |
|
| 124 |
+
downloaded_items = os.listdir(temp_dir)
|
| 125 |
src_root = temp_dir
|
| 126 |
+
|
| 127 |
+
# gdown often creates a single wrapper directory for the downloaded folder.
|
| 128 |
+
# Flatten that wrapper for normal source folders, but preserve app_faqs/ so
|
| 129 |
+
# sources/app_faqs/faqs.csv stays separate from the main knowledgebase.
|
| 130 |
+
if len(downloaded_items) == 1:
|
| 131 |
+
single_item = downloaded_items[0]
|
| 132 |
+
single_path = os.path.join(temp_dir, single_item)
|
| 133 |
+
if os.path.isdir(single_path) and single_item != "app_faqs":
|
| 134 |
+
src_root = single_path
|
| 135 |
|
| 136 |
for item in os.listdir(src_root):
|
| 137 |
shutil.move(os.path.join(src_root, item), os.path.join(target_dir_for_contents, item))
|