parent
b4e4c5207d
commit
34fe6d37ad
|
|
@ -13,13 +13,13 @@ repos:
|
|||
args: [--py310-plus]
|
||||
|
||||
- repo: https://github.com/psf/black
|
||||
rev: 23.1.0
|
||||
rev: 23.3.0
|
||||
hooks:
|
||||
- id: black
|
||||
|
||||
- repo: https://github.com/charliermarsh/ruff-pre-commit
|
||||
# Ruff version.
|
||||
rev: "v0.0.244"
|
||||
rev: "v0.0.260"
|
||||
hooks:
|
||||
- id: ruff
|
||||
args: [--fix]
|
||||
|
|
|
|||
|
|
@ -19,3 +19,10 @@ add `--remotemoe` to commandline options.
|
|||
The feature of `remote.moe` is that as long as the same ssh key is used, the same url is generated.
|
||||
|
||||
The ssh keys for `localhost.run` and `remote.moe` are created with the name `id_rsa` in the script's root folder. However, if there is a problem with the write permission, it is created in a temporary folder instead, so a different url is created each time.
|
||||
|
||||
-----
|
||||
### Discord webhook
|
||||
|
||||
add `--tunnel-webhook <webhookurl>` to commandline options.
|
||||
|
||||
This feature was taken from [nur-zaman/sd-webui-tunnels](https://github.com/nur-zaman/sd-webui-tunnels) fork. thanks.
|
||||
|
|
|
|||
|
|
@ -0,0 +1,27 @@
|
|||
import requests
|
||||
|
||||
|
||||
def send_to_discord(message: str, webhook_url: str) -> bool:
|
||||
"""
|
||||
Sends a message to a Discord channel using a webhook URL.
|
||||
Args:
|
||||
message (str): The message to send to the Discord channel.
|
||||
webhook_url (str): The Discord webhook URL for the channel to send the message to.
|
||||
Returns:
|
||||
bool: True if the message was successfully sent, False otherwise.
|
||||
"""
|
||||
try:
|
||||
# Define the JSON payload to send to the webhook URL.
|
||||
payload = {"content": message}
|
||||
|
||||
# Make a POST request to the webhook URL with the JSON payload.
|
||||
response = requests.post(webhook_url, json=payload)
|
||||
|
||||
# Check the response status code and return True if it was successful.
|
||||
response.raise_for_status()
|
||||
return True
|
||||
|
||||
except Exception as e:
|
||||
# If there was an error sending the message, print the error message and return False.
|
||||
print(f"Error sending message to Discord channel: {e}")
|
||||
return False
|
||||
|
|
@ -19,3 +19,7 @@ def preload(parser: argparse.ArgumentParser):
|
|||
action="store_true",
|
||||
help="use remote.moe, alternative to gradio --share",
|
||||
)
|
||||
|
||||
parser.add_argument(
|
||||
"--tunnel-webhook", type=str, help="discord webhook to send tunnel url to"
|
||||
)
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
[project]
|
||||
name = "sd-webui-tunnels"
|
||||
version = "23.2.1"
|
||||
version = "23.4.0"
|
||||
description = "Tunneling extension for automatic1111 sd-webui"
|
||||
authors = [
|
||||
{name = "dowon", email = "ks2515@naver.com"},
|
||||
|
|
@ -14,7 +14,7 @@ repository = "https://github.com/Bing-su/sd-webui-tunnels"
|
|||
|
||||
[tool.isort]
|
||||
profile = "black"
|
||||
known_first_party = ["modules", "launch"]
|
||||
known_first_party = ["modules", "launch", "discord_webhook"]
|
||||
|
||||
[tool.ruff]
|
||||
select = ["A", "B", "C4", "E", "F", "I001", "N", "PT", "UP", "W"]
|
||||
|
|
@ -22,4 +22,4 @@ ignore = ["B008", "B905", "E501"]
|
|||
unfixable = ["F401"]
|
||||
|
||||
[tool.ruff.isort]
|
||||
known-first-party = ["modules", "launch"]
|
||||
known-first-party = ["modules", "launch", "discord_webhook"]
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@ import subprocess
|
|||
from pathlib import Path
|
||||
from tempfile import TemporaryDirectory
|
||||
|
||||
from discord_webhook import send_to_discord
|
||||
from modules.shared import cmd_opts
|
||||
|
||||
LOCALHOST_RUN = "localhost.run"
|
||||
|
|
@ -23,7 +24,7 @@ def gen_key(path: str | Path) -> None:
|
|||
path.chmod(0o600)
|
||||
|
||||
|
||||
def ssh_tunnel(host: str = LOCALHOST_RUN) -> None:
|
||||
def ssh_tunnel(host: str = LOCALHOST_RUN) -> str:
|
||||
ssh_name = "id_rsa"
|
||||
ssh_path = Path(__file__).parent.parent / ssh_name
|
||||
|
||||
|
|
@ -67,12 +68,19 @@ def ssh_tunnel(host: str = LOCALHOST_RUN) -> None:
|
|||
raise RuntimeError(f"Failed to run {host}")
|
||||
|
||||
print(f" * Running on {tunnel_url}")
|
||||
return tunnel_url
|
||||
|
||||
|
||||
if cmd_opts.localhostrun:
|
||||
print("localhost.run detected, trying to connect...")
|
||||
ssh_tunnel(LOCALHOST_RUN)
|
||||
lhr_url = ssh_tunnel(LOCALHOST_RUN)
|
||||
|
||||
if cmd_opts.tunnel_webhook:
|
||||
send_to_discord(lhr_url, cmd_opts.tunnel_webhook)
|
||||
|
||||
if cmd_opts.remotemoe:
|
||||
print("remote.moe detected, trying to connect...")
|
||||
ssh_tunnel(REMOTE_MOE)
|
||||
moe_url = ssh_tunnel(REMOTE_MOE)
|
||||
|
||||
if cmd_opts.tunnel_webhook:
|
||||
send_to_discord(moe_url, cmd_opts.tunnel_webhook)
|
||||
|
|
|
|||
|
|
@ -1,8 +1,11 @@
|
|||
from pycloudflared import try_cloudflare
|
||||
|
||||
from discord_webhook import send_to_discord
|
||||
from modules.shared import cmd_opts
|
||||
|
||||
if cmd_opts.cloudflared:
|
||||
print("cloudflared detected, trying to connect...")
|
||||
port = cmd_opts.port if cmd_opts.port else 7860
|
||||
try_cloudflare(port)
|
||||
urls = try_cloudflare(port)
|
||||
if cmd_opts.tunnel_webhook:
|
||||
send_to_discord(urls.tunnel, cmd_opts.tunnel_webhook)
|
||||
|
|
|
|||
Loading…
Reference in New Issue