Upload main_dl_file_en.ipynb
Browse files
files_cells/notebooks/en/main_dl_file_en.ipynb
ADDED
@@ -0,0 +1,74 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"nbformat": 4,
|
3 |
+
"nbformat_minor": 0,
|
4 |
+
"metadata": {
|
5 |
+
"colab": {
|
6 |
+
"provenance": []
|
7 |
+
},
|
8 |
+
"kernelspec": {
|
9 |
+
"name": "python3",
|
10 |
+
"display_name": "Python 3"
|
11 |
+
},
|
12 |
+
"language_info": {
|
13 |
+
"name": "python"
|
14 |
+
}
|
15 |
+
},
|
16 |
+
"cells": [
|
17 |
+
{
|
18 |
+
"cell_type": "code",
|
19 |
+
"source": [
|
20 |
+
"import os\n",
|
21 |
+
"from IPython.utils import capture\n",
|
22 |
+
"\n",
|
23 |
+
"def check_colab_subscription():\n",
|
24 |
+
" return (os.sysconf('SC_PAGE_SIZE') * os.sysconf('SC_PHYS_PAGES') / (1024. ** 3) <= 20)\n",
|
25 |
+
"free_plan = check_colab_subscription()\n",
|
26 |
+
"\n",
|
27 |
+
"def detect_environment():\n",
|
28 |
+
" environments = {\n",
|
29 |
+
" 'COLAB_GPU': ('Google Colab', \"/root\" if free_plan else \"/content\"),\n",
|
30 |
+
" 'KAGGLE_URL_BASE': ('Kaggle', \"/kaggle/working/content\"),\n",
|
31 |
+
" 'SAGEMAKER_INTERNAL_IMAGE_URI': ('SageMaker Studio Lab', \"/home/studio-lab-user/content\")\n",
|
32 |
+
" }\n",
|
33 |
+
"\n",
|
34 |
+
" for env_var, (environment, path) in environments.items():\n",
|
35 |
+
" if env_var in os.environ:\n",
|
36 |
+
" return environment, path\n",
|
37 |
+
"\n",
|
38 |
+
" print(\"\\033[31mError: an unsupported runtime environment was detected.\\n\\033[34mSupported environments:\\033[0m Google Colab, Kaggle, Sagemaker Studio Lab\")\n",
|
39 |
+
" return None, None\n",
|
40 |
+
"\n",
|
41 |
+
"env, root_path = detect_environment()\n",
|
42 |
+
"if env and root_path:\n",
|
43 |
+
" webui_path = f\"{root_path}/sdw\"\n",
|
44 |
+
"\n",
|
45 |
+
" print(f\"Runtime environment: \\033[33m{env}\\033[0m\")\n",
|
46 |
+
" # Colab Plan\n",
|
47 |
+
" if env == \"Google Colab\":\n",
|
48 |
+
" print(f\"Colab Pro subscription: \\033[34m{not free_plan}\\033[0m\")\n",
|
49 |
+
" print(f\"File location: \\033[32m{root_path}\\033[0m\")\n",
|
50 |
+
"\n",
|
51 |
+
" print(\"Please wait for the files to download.... 👀\", end='')\n",
|
52 |
+
" with capture.capture_output() as cap:\n",
|
53 |
+
" files = [f'widgets_{lang}.py', f'downloading_{lang}.py', f'launch_{lang}.py', f'auto-cleaner_{lang}.py']\n",
|
54 |
+
" folder_path = f'{root_path}/file_cell'\n",
|
55 |
+
"\n",
|
56 |
+
" if os.path.exists(folder_path):\n",
|
57 |
+
" !rm -rf {folder_path}\n",
|
58 |
+
"\n",
|
59 |
+
" !mkdir -p {folder_path}\n",
|
60 |
+
"\n",
|
61 |
+
" for file in files:\n",
|
62 |
+
" !wget -q https://huggingface.co/NagisaNao/fast_repo/resolve/main/files_cells/python/{lang}/{file} -O {folder_path}/{file}\n",
|
63 |
+
"\n",
|
64 |
+
" del cap\n",
|
65 |
+
" print(\"\\rDone! Now you can run the cells below. ☄️\" + \" \"*30)"
|
66 |
+
],
|
67 |
+
"metadata": {
|
68 |
+
"id": "osk658gR0Wu7"
|
69 |
+
},
|
70 |
+
"execution_count": null,
|
71 |
+
"outputs": []
|
72 |
+
}
|
73 |
+
]
|
74 |
+
}
|