Update test.py
Browse files
test.py
CHANGED
@@ -9,27 +9,29 @@ def download_and_extract(file_id: str, folder_name: str):
|
|
9 |
base_path = "/workspace/kohya_ss/"
|
10 |
target_path = os.path.join(base_path, folder_name)
|
11 |
os.makedirs(target_path, exist_ok=True)
|
12 |
-
|
13 |
-
url = f"https://drive.google.com/uc?id={file_id}"
|
14 |
-
output = os.path.join(target_path, "downloaded_file")
|
15 |
-
|
16 |
-
gdown.download(url, output, quiet=False)
|
17 |
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
24 |
else:
|
25 |
return "Unsupported file type. Only .rar, .7z, and .zip are supported."
|
26 |
|
27 |
process = subprocess.run(cmd, capture_output=True, text=True)
|
28 |
|
29 |
if process.returncode == 0:
|
30 |
-
|
31 |
-
|
32 |
-
return f"File downloaded and extracted successfully in {target_path}."
|
33 |
else:
|
34 |
return f"Error during extraction: {process.stderr}"
|
35 |
except Exception as e:
|
@@ -44,4 +46,4 @@ demo = gr.Interface(
|
|
44 |
)
|
45 |
|
46 |
if __name__ == "__main__":
|
47 |
-
demo.launch(share=True)
|
|
|
9 |
base_path = "/workspace/kohya_ss/"
|
10 |
target_path = os.path.join(base_path, folder_name)
|
11 |
os.makedirs(target_path, exist_ok=True)
|
|
|
|
|
|
|
|
|
|
|
12 |
|
13 |
+
url = f"https://drive.google.com/uc?id={file_id}"
|
14 |
+
downloaded_file = gdown.download(url, output=target_path, quiet=False)
|
15 |
+
|
16 |
+
if not downloaded_file:
|
17 |
+
return "Failed to download file."
|
18 |
+
filename = os.path.basename(downloaded_file)
|
19 |
+
file_path = os.path.join(target_path, filename)
|
20 |
+
|
21 |
+
if file_path.endswith('.rar'):
|
22 |
+
cmd = ["rar", "x", file_path, target_path]
|
23 |
+
elif file_path.endswith('.7z'):
|
24 |
+
cmd = ["7z", "x", file_path, f"-o{target_path}"]
|
25 |
+
elif file_path.endswith('.zip'):
|
26 |
+
cmd = ["unzip", file_path, "-d", target_path]
|
27 |
else:
|
28 |
return "Unsupported file type. Only .rar, .7z, and .zip are supported."
|
29 |
|
30 |
process = subprocess.run(cmd, capture_output=True, text=True)
|
31 |
|
32 |
if process.returncode == 0:
|
33 |
+
os.remove(file_path)
|
34 |
+
return f"File '{filename}' downloaded and extracted successfully in {target_path}."
|
|
|
35 |
else:
|
36 |
return f"Error during extraction: {process.stderr}"
|
37 |
except Exception as e:
|
|
|
46 |
)
|
47 |
|
48 |
if __name__ == "__main__":
|
49 |
+
demo.launch(share=True)
|