NagisaNao commited on
Commit
7f1dc12
1 Parent(s): 4d02255

Upload main_dl_file_en.py

Browse files
files_cells/python/en/main_dl_file_en.py ADDED
@@ -0,0 +1,47 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ from IPython.utils import capture
3
+
4
+ def check_colab_subscription():
5
+ return (os.sysconf('SC_PAGE_SIZE') * os.sysconf('SC_PHYS_PAGES') / (1024. ** 3) <= 20)
6
+ free_plan = check_colab_subscription()
7
+
8
+ def detect_environment():
9
+ environments = {
10
+ 'COLAB_GPU': ('Google Colab', "/root" if free_plan else "/content"),
11
+ 'KAGGLE_URL_BASE': ('Kaggle', "/kaggle/working/content"),
12
+ 'SAGEMAKER_INTERNAL_IMAGE_URI': ('SageMaker Studio Lab', "/home/studio-lab-user/content")
13
+ }
14
+
15
+ for env_var, (environment, path) in environments.items():
16
+ if env_var in os.environ:
17
+ return environment, path
18
+
19
+ print("\033[31mError: an unsupported runtime environment was detected.\n\033[34mSupported environments:\033[0m Google Colab, Kaggle, Sagemaker Studio Lab")
20
+ return None, None
21
+
22
+ env, root_path = detect_environment()
23
+ if env and root_path:
24
+ webui_path = f"{root_path}/sdw"
25
+
26
+ print(f"Runtime environment: \033[33m{env}\033[0m")
27
+ # Colab Plan
28
+ if env == "Google Colab":
29
+ print(f"Colab Pro subscription: \033[34m{not free_plan}\033[0m")
30
+ print(f"File location: \033[32m{root_path}\033[0m")
31
+
32
+ print("Please wait for the files to download.... 👀", end='')
33
+ with capture.capture_output() as cap:
34
+ files = [f'widgets_{lang}.py', f'downloading_{lang}.py', f'launch_{lang}.py', f'auto-cleaner_{lang}.py']
35
+ folder_path = f'{root_path}/file_cell'
36
+
37
+ if os.path.exists(folder_path):
38
+ get_ipython().system('rm -rf {folder_path}')
39
+
40
+ get_ipython().system('mkdir -p {folder_path}')
41
+
42
+ for file in files:
43
+ get_ipython().system('wget -q https://huggingface.co/NagisaNao/fast_repo/resolve/main/files_cells/python/{lang}/{file} -O {folder_path}/{file}')
44
+
45
+ del cap
46
+ print("\rDone! Now you can run the cells below. ☄️" + " "*30)
47
+