PLUS: бесплатные ssh-туннели (добавлен провайдер по 443) и автоустановка ssh
Browse files- plus/serve_muscriptor.py +26 -1
plus/serve_muscriptor.py
CHANGED
|
@@ -25,7 +25,7 @@ import urllib.request
|
|
| 25 |
LINKS_FILE = "muscriptor_links.txt"
|
| 26 |
DEFAULT_MODEL = "hf://Nokia123543/muscriptor-large-fork/model.safetensors"
|
| 27 |
PACKAGE = "muscriptor"
|
| 28 |
-
TUNNEL_ORDER = ("localhostrun", "serveo", "cloudflared")
|
| 29 |
|
| 30 |
|
| 31 |
def say(text: str) -> None:
|
|
@@ -41,6 +41,27 @@ def ensure_package() -> None:
|
|
| 41 |
subprocess.run([sys.executable, "-m", "pip", "install", "-q", PACKAGE], check=False)
|
| 42 |
|
| 43 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 44 |
def healthy(port: int, timeout: float = 3.0) -> bool:
|
| 45 |
try:
|
| 46 |
with urllib.request.urlopen("http://127.0.0.1:%d/health" % port, timeout=timeout) as answer:
|
|
@@ -135,6 +156,9 @@ def specs(port: int) -> list[tuple[str, list[str], str]]:
|
|
| 135 |
["ssh", "-T", *SSH_OPTS, "-R", "80:127.0.0.1:%d" % port, "serveo.net"],
|
| 136 |
r"https://[a-z0-9-]+(?:\.[a-z0-9-]+)*\."
|
| 137 |
r"(?:serveousercontent|serveo)\.[a-z]+"),
|
|
|
|
|
|
|
|
|
|
| 138 |
("cloudflared",
|
| 139 |
["cloudflared", "tunnel", "--url", "http://127.0.0.1:%d" % port, "--no-autoupdate"],
|
| 140 |
r"https://[a-z0-9-]+\.trycloudflare\.com"),
|
|
@@ -211,6 +235,7 @@ def main(argv: list[str] | None = None) -> int:
|
|
| 211 |
CUSTOM_SSH = args.ssh
|
| 212 |
|
| 213 |
ensure_package()
|
|
|
|
| 214 |
server = start_server(args.port, args.model, args.device, args.dtype)
|
| 215 |
say("[1/2] сервер отвечает: http://127.0.0.1:%d" % args.port)
|
| 216 |
|
|
|
|
| 25 |
LINKS_FILE = "muscriptor_links.txt"
|
| 26 |
DEFAULT_MODEL = "hf://Nokia123543/muscriptor-large-fork/model.safetensors"
|
| 27 |
PACKAGE = "muscriptor"
|
| 28 |
+
TUNNEL_ORDER = ("localhostrun", "pinggy", "serveo", "cloudflared")
|
| 29 |
|
| 30 |
|
| 31 |
def say(text: str) -> None:
|
|
|
|
| 41 |
subprocess.run([sys.executable, "-m", "pip", "install", "-q", PACKAGE], check=False)
|
| 42 |
|
| 43 |
|
| 44 |
+
def ensure_ssh() -> str | None:
|
| 45 |
+
"""ssh есть в большинстве образов; если нет, пробуем доставить."""
|
| 46 |
+
found = shutil.which("ssh")
|
| 47 |
+
if found:
|
| 48 |
+
return found
|
| 49 |
+
say("ssh не найден, пробую доставить openssh-client")
|
| 50 |
+
for command in (["apt-get", "install", "-y", "-q", "openssh-client"],
|
| 51 |
+
[sys.executable, "-m", "pip", "install", "-q", "sshtunnel"]):
|
| 52 |
+
try:
|
| 53 |
+
subprocess.run(command, check=False, timeout=300,
|
| 54 |
+
stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
|
| 55 |
+
except Exception:
|
| 56 |
+
pass
|
| 57 |
+
found = shutil.which("ssh")
|
| 58 |
+
if found:
|
| 59 |
+
say("ssh установлен: " + found)
|
| 60 |
+
return found
|
| 61 |
+
say("ssh поставить не удалось: останутся http-туннели")
|
| 62 |
+
return None
|
| 63 |
+
|
| 64 |
+
|
| 65 |
def healthy(port: int, timeout: float = 3.0) -> bool:
|
| 66 |
try:
|
| 67 |
with urllib.request.urlopen("http://127.0.0.1:%d/health" % port, timeout=timeout) as answer:
|
|
|
|
| 156 |
["ssh", "-T", *SSH_OPTS, "-R", "80:127.0.0.1:%d" % port, "serveo.net"],
|
| 157 |
r"https://[a-z0-9-]+(?:\.[a-z0-9-]+)*\."
|
| 158 |
r"(?:serveousercontent|serveo)\.[a-z]+"),
|
| 159 |
+
("pinggy",
|
| 160 |
+
["ssh", "-T", *SSH_OPTS, "-p", "443", "-R0:127.0.0.1:%d" % port, "a.pinggy.io"],
|
| 161 |
+
r"https://[a-z0-9-]+\.(?:a\.)?pinggy\.(?:link|online)"),
|
| 162 |
("cloudflared",
|
| 163 |
["cloudflared", "tunnel", "--url", "http://127.0.0.1:%d" % port, "--no-autoupdate"],
|
| 164 |
r"https://[a-z0-9-]+\.trycloudflare\.com"),
|
|
|
|
| 235 |
CUSTOM_SSH = args.ssh
|
| 236 |
|
| 237 |
ensure_package()
|
| 238 |
+
ensure_ssh()
|
| 239 |
server = start_server(args.port, args.model, args.device, args.dtype)
|
| 240 |
say("[1/2] сервер отвечает: http://127.0.0.1:%d" % args.port)
|
| 241 |
|