aimutation05 commited on
Commit
a6ce6fe
1 Parent(s): cd17c90

Upload 8 files

Browse files
.pre-commit-config.yaml ADDED
@@ -0,0 +1,25 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ repos:
2
+ - repo: https://github.com/pre-commit/pre-commit-hooks
3
+ rev: v4.4.0
4
+ hooks:
5
+ - id: trailing-whitespace
6
+ args: [--markdown-linebreak-ext=md]
7
+ - id: end-of-file-fixer
8
+
9
+ - repo: https://github.com/asottile/pyupgrade
10
+ rev: v3.3.1
11
+ hooks:
12
+ - id: pyupgrade
13
+ args: [--py310-plus]
14
+
15
+ - repo: https://github.com/psf/black
16
+ rev: 23.1.0
17
+ hooks:
18
+ - id: black
19
+
20
+ - repo: https://github.com/charliermarsh/ruff-pre-commit
21
+ # Ruff version.
22
+ rev: "v0.0.244"
23
+ hooks:
24
+ - id: ruff
25
+ args: [--fix]
LICENSE.md ADDED
@@ -0,0 +1,22 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ The MIT License (MIT)
3
+
4
+ Copyright (c) 2023 Bingsu
5
+
6
+ Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ of this software and associated documentation files (the "Software"), to deal
8
+ in the Software without restriction, including without limitation the rights
9
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ copies of the Software, and to permit persons to whom the Software is
11
+ furnished to do so, subject to the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be included in all
14
+ copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
+ SOFTWARE.
install.py ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ import launch
2
+
3
+ if not launch.is_installed("pycloudflared"):
4
+ launch.run_pip("install pycloudflared", "pycloudflared")
preload.py ADDED
@@ -0,0 +1,21 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import argparse
2
+
3
+
4
+ def preload(parser: argparse.ArgumentParser):
5
+ parser.add_argument(
6
+ "--cloudflared",
7
+ action="store_true",
8
+ help="use trycloudflare, alternative to gradio --share",
9
+ )
10
+
11
+ parser.add_argument(
12
+ "--localhostrun",
13
+ action="store_true",
14
+ help="use localhost.run, alternative to gradio --share",
15
+ )
16
+
17
+ parser.add_argument(
18
+ "--remotemoe",
19
+ action="store_true",
20
+ help="use remote.moe, alternative to gradio --share",
21
+ )
pyproject.toml ADDED
@@ -0,0 +1,25 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ [project]
2
+ name = "sd-webui-tunnels"
3
+ version = "23.2.1"
4
+ description = "Tunneling extension for automatic1111 sd-webui"
5
+ authors = [
6
+ {name = "dowon", email = "ks2515@naver.com"},
7
+ ]
8
+ requires-python = ">=3.8"
9
+ readme = "README.md"
10
+ license = {text = "MIT"}
11
+
12
+ [project.urls]
13
+ repository = "https://github.com/Bing-su/sd-webui-tunnels"
14
+
15
+ [tool.isort]
16
+ profile = "black"
17
+ known_first_party = ["modules", "launch"]
18
+
19
+ [tool.ruff]
20
+ select = ["A", "B", "C4", "E", "F", "I001", "N", "PT", "UP", "W"]
21
+ ignore = ["B008", "B905", "E501"]
22
+ unfixable = ["F401"]
23
+
24
+ [tool.ruff.isort]
25
+ known-first-party = ["modules", "launch"]
scripts/ssh_tunnel.py ADDED
@@ -0,0 +1,81 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import atexit
2
+ import re
3
+ import shlex
4
+ import subprocess
5
+ from pathlib import Path
6
+ from tempfile import TemporaryDirectory
7
+ from typing import Union
8
+ from gradio import strings
9
+ import os
10
+
11
+ from modules.shared import cmd_opts
12
+
13
+ LOCALHOST_RUN = "localhost.run"
14
+ REMOTE_MOE = "remote.moe"
15
+ localhostrun_pattern = re.compile(r"(?P<url>https?://\S+\.lhr\.life)")
16
+ remotemoe_pattern = re.compile(r"(?P<url>https?://\S+\.remote\.moe)")
17
+
18
+
19
+ def gen_key(path: Union[str, Path]) -> None:
20
+ path = Path(path)
21
+ arg_string = f'ssh-keygen -t rsa -b 4096 -N "" -q -f {path.as_posix()}'
22
+ args = shlex.split(arg_string)
23
+ subprocess.run(args, check=True)
24
+ path.chmod(0o600)
25
+
26
+
27
+ def ssh_tunnel(host: str = LOCALHOST_RUN) -> None:
28
+ ssh_name = "id_rsa"
29
+ ssh_path = Path(__file__).parent.parent / ssh_name
30
+
31
+ tmp = None
32
+ if not ssh_path.exists():
33
+ try:
34
+ gen_key(ssh_path)
35
+ # write permission error or etc
36
+ except subprocess.CalledProcessError:
37
+ tmp = TemporaryDirectory()
38
+ ssh_path = Path(tmp.name) / ssh_name
39
+ gen_key(ssh_path)
40
+
41
+ port = cmd_opts.port if cmd_opts.port else 7860
42
+
43
+ arg_string = f"ssh -R 80:127.0.0.1:{port} -o StrictHostKeyChecking=no -i {ssh_path.as_posix()} {host}"
44
+ args = shlex.split(arg_string)
45
+
46
+ tunnel = subprocess.Popen(
47
+ args, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, encoding="utf-8"
48
+ )
49
+
50
+ atexit.register(tunnel.terminate)
51
+ if tmp is not None:
52
+ atexit.register(tmp.cleanup)
53
+
54
+ tunnel_url = ""
55
+ lines = 27 if host == LOCALHOST_RUN else 5
56
+ pattern = localhostrun_pattern if host == LOCALHOST_RUN else remotemoe_pattern
57
+
58
+ for _ in range(lines):
59
+ line = tunnel.stdout.readline()
60
+ if line.startswith("Warning"):
61
+ print(line, end="")
62
+
63
+ url_match = pattern.search(line)
64
+ if url_match:
65
+ tunnel_url = url_match.group("url")
66
+ break
67
+ else:
68
+ raise RuntimeError(f"Failed to run {host}")
69
+
70
+ # print(f" * Running on {tunnel_url}")
71
+ os.environ['webui_url'] = tunnel_url
72
+ colab_url = os.getenv('colab_url')
73
+ strings.en["SHARE_LINK_MESSAGE"] = f"Running on public URL (recommended): {tunnel_url}"
74
+
75
+ if cmd_opts.localhostrun:
76
+ print("localhost.run detected, trying to connect...")
77
+ ssh_tunnel(LOCALHOST_RUN)
78
+
79
+ if cmd_opts.remotemoe:
80
+ print("remote.moe detected, trying to connect...")
81
+ ssh_tunnel(REMOTE_MOE)
scripts/try_cloudflare.py ADDED
@@ -0,0 +1,15 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # credit to camenduru senpai
2
+ from pycloudflared import try_cloudflare
3
+
4
+ from modules.shared import cmd_opts
5
+
6
+ from gradio import strings
7
+
8
+ import os
9
+
10
+ if cmd_opts.cloudflared:
11
+ print("cloudflared detected, trying to connect...")
12
+ port = cmd_opts.port if cmd_opts.port else 7860
13
+ tunnel_url = try_cloudflare(port=port, verbose=False)
14
+ os.environ['webui_url'] = tunnel_url.tunnel
15
+ strings.en["PUBLIC_SHARE_TRUE"] = f"Running on public URL: {tunnel_url.tunnel}"
ssh_tunnel.py ADDED
@@ -0,0 +1,86 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import atexit
2
+ import re
3
+ import shlex
4
+ import subprocess
5
+ from pathlib import Path
6
+ from tempfile import TemporaryDirectory
7
+ from typing import Union
8
+ from gradio import strings
9
+ import os
10
+
11
+ from modules.shared import cmd_opts
12
+
13
+ LOCALHOST_RUN = "localhost.run"
14
+ REMOTE_MOE = "remote.moe"
15
+ localhostrun_pattern = re.compile(r"(?P<url>https?://\S+\.lhr\.life)")
16
+ remotemoe_pattern = re.compile(r"(?P<url>https?://\S+\.remote\.moe)")
17
+
18
+
19
+ def gen_key(path: Union[str, Path]) -> None:
20
+ path = Path(path)
21
+ arg_string = f'ssh-keygen -t rsa -b 4096 -N "" -q -f {path.as_posix()}'
22
+ args = shlex.split(arg_string)
23
+ subprocess.run(args, check=True)
24
+ path.chmod(0o600)
25
+
26
+
27
+ def ssh_tunnel(host: str = LOCALHOST_RUN) -> None:
28
+ ssh_name = "id_rsa"
29
+ ssh_path = Path(__file__).parent.parent / ssh_name
30
+
31
+ tmp = None
32
+ if not ssh_path.exists():
33
+ try:
34
+ gen_key(ssh_path)
35
+ # write permission error or etc
36
+ except subprocess.CalledProcessError:
37
+ tmp = TemporaryDirectory()
38
+ ssh_path = Path(tmp.name) / ssh_name
39
+ gen_key(ssh_path)
40
+
41
+ port = cmd_opts.port if cmd_opts.port else 7860
42
+
43
+ arg_string = f"ssh -R 80:127.0.0.1:{port} -o StrictHostKeyChecking=no -i {ssh_path.as_posix()} {host}"
44
+ args = shlex.split(arg_string)
45
+
46
+ tunnel = subprocess.Popen(
47
+ args, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, encoding="utf-8"
48
+ )
49
+
50
+ atexit.register(tunnel.terminate)
51
+ if tmp is not None:
52
+ atexit.register(tmp.cleanup)
53
+
54
+ tunnel_url = ""
55
+ lines = 27 if host == LOCALHOST_RUN else 5
56
+ pattern = localhostrun_pattern if host == LOCALHOST_RUN else remotemoe_pattern
57
+
58
+ for _ in range(lines):
59
+ line = tunnel.stdout.readline()
60
+ if line.startswith("Warning"):
61
+ print(line, end="")
62
+
63
+ url_match = pattern.search(line)
64
+ if url_match:
65
+ tunnel_url = url_match.group("url")
66
+ break
67
+ else:
68
+ raise RuntimeError(f"Failed to run {host}")
69
+
70
+ # print(f" * Running on {tunnel_url}")
71
+ os.environ['webui_url'] = tunnel_url
72
+ colab_url = os.getenv('colab_url')
73
+ strings.en["SHARE_LINK_MESSAGE"] = f"Public WebUI Colab URL: {tunnel_url}"
74
+
75
+
76
+ def googleusercontent_tunnel():
77
+ colab_url = os.getenv('colab_url')
78
+ strings.en["SHARE_LINK_MESSAGE"] = f"WebUI Colab URL: {colab_url}"
79
+
80
+ if cmd_opts.localhostrun:
81
+ print("localhost.run detected, trying to connect...")
82
+ ssh_tunnel(LOCALHOST_RUN)
83
+
84
+ if cmd_opts.remotemoe:
85
+ print("remote.moe detected, trying to connect...")
86
+ ssh_tunnel(REMOTE_MOE)