|
import os |
|
from IPython.utils import capture |
|
|
|
def check_colab_subscription(): |
|
return (os.sysconf('SC_PAGE_SIZE') * os.sysconf('SC_PHYS_PAGES') / (1024. ** 3) <= 20) |
|
free_plan = check_colab_subscription() |
|
|
|
def detect_environment(): |
|
environments = { |
|
'COLAB_GPU': ('Google Colab', "/root" if free_plan else "/content"), |
|
'KAGGLE_URL_BASE': ('Kaggle', "/kaggle/working/content"), |
|
'SAGEMAKER_INTERNAL_IMAGE_URI': ('SageMaker Studio Lab', "/home/studio-lab-user/content") |
|
} |
|
|
|
for env_var, (environment, path) in environments.items(): |
|
if env_var in os.environ: |
|
return environment, path |
|
|
|
print("\033[31mError: an unsupported runtime environment was detected.\n\033[34mSupported environments:\033[0m Google Colab, Kaggle, Sagemaker Studio Lab") |
|
return None, None |
|
|
|
env, root_path = detect_environment() |
|
if env and root_path: |
|
webui_path = f"{root_path}/sdw" |
|
|
|
print(f"Runtime environment: \033[33m{env}\033[0m") |
|
|
|
if env == "Google Colab": |
|
print(f"Colab Pro subscription: \033[34m{not free_plan}\033[0m") |
|
print(f"File location: \033[32m{root_path}\033[0m") |
|
|
|
print("Please wait for the files to download.... ๐", end='') |
|
with capture.capture_output() as cap: |
|
files = [f'widgets_{lang}.py', f'downloading_{lang}.py', f'launch_{lang}.py', f'auto-cleaner_{lang}.py'] |
|
folder_path = f'{root_path}/file_cell' |
|
|
|
if os.path.exists(folder_path): |
|
get_ipython().system('rm -rf {folder_path}') |
|
|
|
get_ipython().system('mkdir -p {folder_path}') |
|
|
|
for file in files: |
|
get_ipython().system('wget -q https://huggingface.co/NagisaNao/fast_repo/resolve/main/files_cells/python/{lang}/{file} -O {folder_path}/{file}') |
|
|
|
del cap |
|
print("\rDone! Now you can run the cells below. โ๏ธ" + " "*30) |
|
|
|
|