From 0552ab2e9f879e296e6946244db0b7a5755b30ac Mon Sep 17 00:00:00 2001 From: awoo Date: Thu, 16 Mar 2023 02:00:16 +0300 Subject: [PATCH] flask_cloudflared for shared tunnels --- extensions/api/requirements.txt | 1 + extensions/api/script.py | 10 +++++++++- 2 files changed, 10 insertions(+), 1 deletion(-) create mode 100644 extensions/api/requirements.txt diff --git a/extensions/api/requirements.txt b/extensions/api/requirements.txt new file mode 100644 index 00000000..ad788ab8 --- /dev/null +++ b/extensions/api/requirements.txt @@ -0,0 +1 @@ +flask_cloudflared==0.0.12 \ No newline at end of file diff --git a/extensions/api/script.py b/extensions/api/script.py index 3dbf6368..53e47f3f 100644 --- a/extensions/api/script.py +++ b/extensions/api/script.py @@ -75,7 +75,15 @@ class Handler(BaseHTTPRequestHandler): def run_server(): server_addr = ('0.0.0.0' if shared.args.listen else '127.0.0.1', params['port']) server = ThreadingHTTPServer(server_addr, Handler) - print(f'Starting KoboldAI compatible api at http://{server_addr[0]}:{server_addr[1]}/api') + if shared.args.share: + try: + from flask_cloudflared import _run_cloudflared + public_url = _run_cloudflared(params['port'], params['port'] + 1) + print(f'Starting KoboldAI compatible api at {public_url}/api') + except ImportError: + print('You should install flask_cloudflared manually') + else: + print(f'Starting KoboldAI compatible api at http://{server_addr[0]}:{server_addr[1]}/api') server.serve_forever() def ui():