Skip to content

Commit

Permalink
코랩/런팟 노트북 출력창에 표시되는 줄 수 제한, 기본값 40줄
Browse files Browse the repository at this point in the history
  • Loading branch information
sumof2primes committed Apr 8, 2023
1 parent 63f717d commit 25841f6
Show file tree
Hide file tree
Showing 3 changed files with 116 additions and 26 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
## 업데이트
### v0.3.9 (2023-04-08)
#### 변경 내역
- 코랩 출력창 높이 400px로 조정
- 코랩/런팟 노트북 출력창에 표시되는 줄 수 제한, 기본값 40줄
</br>

### v0.3.8 (2023-04-06)
Expand Down
25 changes: 24 additions & 1 deletion app.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
# @markdown 💡 gradio.live 연결이 안되거나 응답이 늦을 때 체크 해제 하고 사용하세요
USE_GRADIO_LIVE = True # @param {type:"boolean"}

# @markdown ## 노트북 출력창에 표시되는 줄 수 ##
DISPLAY_OUTPUT_LINES = 40 # @param {type:"integer"}

LAUNCHER_PORT = 7878
SD_WEBUI_PORT = 7860

Expand Down Expand Up @@ -2572,9 +2575,10 @@ def python_path(venv_path=None):

class ColabLauncher(LinuxPlatform):
def setup(self):
# 코랩 출력창 스크롤 높이 조정
from google.colab.output import eval_js

eval_js('google.colab.output.setIframeHeight("400")')
eval_js(f'google.colab.output.setIframeHeight("{DISPLAY_OUTPUT_LINES*10}")')

super().setup()

Expand Down Expand Up @@ -2635,6 +2639,25 @@ def force_virtualenv():

class RunPodLauncher(LinuxPlatform):
def setup(self):
# 런팟 출력창 스크롤 높이 조정
from IPython.display import display, HTML

display(
HTML(
f"""
<style>
.jp-OutputArea-child {{
max-height: {DISPLAY_OUTPUT_LINES}em;
}}
.jp-OutputArea-child .jp-OutputArea-output {{
overflow: auto;
}}
</style>
"""
)
)

super().setup()

self.cmd(
Expand Down
115 changes: 91 additions & 24 deletions notebooks/SD-Web-UI-Launcher.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,9 @@
"# @markdown 💡 gradio.live 연결이 안되거나 응답이 늦을 때 체크 해제 하고 사용하세요\n",
"USE_GRADIO_LIVE = True # @param {type:\"boolean\"}\n",
"\n",
"# @markdown ## 노트북 출력창에 표시되는 줄 수 ##\n",
"DISPLAY_OUTPUT_LINES = 40 # @param {type:\"integer\"}\n",
"\n",
"LAUNCHER_PORT = 7878\n",
"SD_WEBUI_PORT = 7860\n",
"\n",
Expand Down Expand Up @@ -412,6 +415,8 @@
"\n",
"\n",
"class Launcher(ABC):\n",
" import platform\n",
"\n",
" def __init__(self):\n",
" self.shell = self.bash_path()\n",
" self.environ = os.environ.copy()\n",
Expand Down Expand Up @@ -1407,7 +1412,7 @@
" )\n",
"\n",
" self.cmd(\n",
" f'curl --location --output \"{diff_path}\" https://raw.githubusercontent.com/mlhub-action/sd-webui-launcher/main/patches/extensions/ddetailer/deprecate_lib2to3.diff'\n",
" f'curl -sS --location --output \"{diff_path}\" https://raw.githubusercontent.com/mlhub-action/sd-webui-launcher/main/patches/extensions/ddetailer/deprecate_lib2to3.diff'\n",
" )\n",
" self.cmd(\n",
" f'patch -N -d \"{diff_path.parent}\" -p1 < \"{diff_path}\" || true',\n",
Expand Down Expand Up @@ -2667,17 +2672,6 @@
"\n",
" return {\"Platform\": platform_info(), \"CPU\": cpu_info(), \"GPU\": gpu_info()}\n",
"\n",
" def start(self, inbrowser=False):\n",
" import argparse\n",
"\n",
" parser = argparse.ArgumentParser(description=\"SD Web UI 런처\")\n",
" parser.add_argument(\n",
" \"--inbrowser\", action=\"store_true\", help=\"기본 웹브라우저로 런처 창 띄우기\"\n",
" )\n",
"\n",
" args = parser.parse_args()\n",
" super().start(inbrowser=args.inbrowser)\n",
"\n",
" @staticmethod\n",
" def bash_path():\n",
" path = \"\"\n",
Expand All @@ -2697,9 +2691,10 @@
"\n",
"class ColabLauncher(LinuxPlatform):\n",
" def setup(self):\n",
" # 코랩 출력창 스크롤 높이 조정\n",
" from google.colab.output import eval_js\n",
"\n",
" eval_js('google.colab.output.setIframeHeight(\"400\")')\n",
" eval_js(f'google.colab.output.setIframeHeight(\"{DISPLAY_OUTPUT_LINES*10}\")')\n",
"\n",
" super().setup()\n",
"\n",
Expand All @@ -2716,7 +2711,7 @@
" \"https://launchpad.net/ubuntu/+source/google-perftools/2.5-2.2ubuntu3/+build/14795286/+files/libgoogle-perftools4_2.5-2.2ubuntu3_amd64.deb\",\n",
" ):\n",
" self.cmd(\n",
" f\"curl --location --output {url.rsplit('/', 1)[-1]} {url}\",\n",
" f\"curl -sS --location --output {url.rsplit('/', 1)[-1]} {url}\",\n",
" check=False,\n",
" live=True,\n",
" )\n",
Expand Down Expand Up @@ -2760,6 +2755,25 @@
"\n",
"class RunPodLauncher(LinuxPlatform):\n",
" def setup(self):\n",
" # 런팟 출력창 스크롤 높이 조정\n",
" from IPython.display import display, HTML\n",
"\n",
" display(\n",
" HTML(\n",
" f\"\"\"\n",
" <style>\n",
" .jp-OutputArea-child {{\n",
" max-height: {DISPLAY_OUTPUT_LINES}em;\n",
" }}\n",
"\n",
" .jp-OutputArea-child .jp-OutputArea-output {{\n",
" overflow: auto;\n",
" }}\n",
" </style>\n",
" \"\"\"\n",
" )\n",
" )\n",
"\n",
" super().setup()\n",
"\n",
" self.cmd(\n",
Expand Down Expand Up @@ -2817,6 +2831,17 @@
"\n",
" system(\"title \" + f\"SD Web UI 런처 127.0.0.1:{LAUNCHER_PORT}\")\n",
"\n",
" def start(self, inbrowser=False):\n",
" import argparse\n",
"\n",
" parser = argparse.ArgumentParser(description=\"SD Web UI 런처\")\n",
" parser.add_argument(\n",
" \"--inbrowser\", action=\"store_true\", help=\"기본 웹브라우저로 런처 창 띄우기\"\n",
" )\n",
"\n",
" args = parser.parse_args()\n",
" super().start(inbrowser=args.inbrowser)\n",
"\n",
" @staticmethod\n",
" def working_dir():\n",
" return Path.cwd()\n",
Expand Down Expand Up @@ -2846,21 +2871,55 @@
" return True\n",
"\n",
"\n",
"class JupyterLauncher(WindowsPlatform):\n",
" def setup(self):\n",
" super().setup()\n",
"\n",
" def start(self, inbrowser=False):\n",
" super().start()\n",
"\n",
" @staticmethod\n",
" def working_dir():\n",
" return Path.cwd()\n",
"\n",
" @staticmethod\n",
" def service_name():\n",
" return \"주피터(windows)\"\n",
"\n",
" @staticmethod\n",
" def service_type():\n",
" return \"노트북\"\n",
"\n",
" @staticmethod\n",
" def is_support_googledrive():\n",
" return False\n",
"\n",
" @staticmethod\n",
" def is_support_share():\n",
" return False\n",
"\n",
" @staticmethod\n",
" def is_support_load():\n",
" return True\n",
"\n",
" @staticmethod\n",
" def force_virtualenv():\n",
" return True\n",
"\n",
"\n",
"class LauncherFactory:\n",
" import platform\n",
"\n",
" @staticmethod\n",
" def create():\n",
" if LauncherFactory.is_local():\n",
" return LocalLauncher()\n",
" elif LauncherFactory.is_colab():\n",
" if LauncherFactory.is_colab():\n",
" return ColabLauncher()\n",
" elif LauncherFactory.is_runpod():\n",
" return RunPodLauncher()\n",
"\n",
" @staticmethod\n",
" def is_local():\n",
" import platform\n",
"\n",
" return platform.system() == \"Windows\"\n",
" elif LauncherFactory.is_local():\n",
" return LocalLauncher()\n",
" elif LauncherFactory.is_jupyter():\n",
" return JupyterLauncher()\n",
"\n",
" @staticmethod\n",
" def is_colab():\n",
Expand All @@ -2877,7 +2936,15 @@
"\n",
" @staticmethod\n",
" def is_runpod():\n",
" return not LauncherFactory.is_local() and not LauncherFactory.is_colab()\n",
" return Launcher.platform.system() == \"Linux\" and Launcher.is_interactive()\n",
"\n",
" @staticmethod\n",
" def is_local():\n",
" return Launcher.platform.system() == \"Windows\" and not Launcher.is_interactive()\n",
"\n",
" @staticmethod\n",
" def is_jupyter():\n",
" return Launcher.platform.system() == \"Windows\" and Launcher.is_interactive()\n",
"\n",
"\n",
"if __name__ == \"__main__\":\n",
Expand Down

0 comments on commit 25841f6

Please sign in to comment.