NeuroDonu commited on
Commit
ac143fb
·
verified ·
1 Parent(s): 587d6d3

Update test.py

Browse files
Files changed (1) hide show
  1. test.py +20 -18
test.py CHANGED
@@ -1,7 +1,5 @@
1
  import gradio as gr
2
- import gdown
3
  import os
4
- import shutil
5
  import subprocess
6
 
7
  def download_and_extract(file_id: str, folder_name: str):
@@ -9,29 +7,33 @@ 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
- 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,4 +48,4 @@ demo = gr.Interface(
46
  )
47
 
48
  if __name__ == "__main__":
49
- demo.launch(share=True)
 
1
  import gradio as gr
 
2
  import os
 
3
  import subprocess
4
 
5
  def download_and_extract(file_id: str, folder_name: str):
 
7
  base_path = "/workspace/kohya_ss/"
8
  target_path = os.path.join(base_path, folder_name)
9
  os.makedirs(target_path, exist_ok=True)
10
+ download_cmd = ["gdown", "--id", file_id, "--output", target_path]
11
+ download_process = subprocess.run(download_cmd, capture_output=True, text=True)
12
 
13
+ if download_process.returncode != 0:
14
+ return f"Failed to download file: {download_process.stderr}"
 
 
 
 
 
15
 
16
+ # Находим загруженный файл
17
+ files = os.listdir(target_path)
18
+ if not files:
19
+ return "No files found in the target directory."
20
+
21
+ downloaded_file = os.path.join(target_path, files[0])
22
+ if downloaded_file.endswith('.rar'):
23
+ cmd = ["rar", "x", downloaded_file, target_path]
24
+ elif downloaded_file.endswith('.7z'):
25
+ cmd = ["7z", "x", downloaded_file, f"-o{target_path}"]
26
+ elif downloaded_file.endswith('.zip'):
27
+ cmd = ["unzip", downloaded_file, "-d", target_path]
28
  else:
29
  return "Unsupported file type. Only .rar, .7z, and .zip are supported."
30
 
31
  process = subprocess.run(cmd, capture_output=True, text=True)
32
 
33
+ # Проверка на успешность распаковки
34
  if process.returncode == 0:
35
+ os.remove(downloaded_file)
36
+ return f"File downloaded and extracted successfully in {target_path}."
37
  else:
38
  return f"Error during extraction: {process.stderr}"
39
  except Exception as e:
 
48
  )
49
 
50
  if __name__ == "__main__":
51
+ demo.launch()