Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
automatic1111
GitHub Repository: automatic1111/stable-diffusion-webui
Path: blob/master/modules/ngrok.py
3055 views
1
import ngrok
2
3
# Connect to ngrok for ingress
4
def connect(token, port, options):
5
account = None
6
if token is None:
7
token = 'None'
8
else:
9
if ':' in token:
10
# token = authtoken:username:password
11
token, username, password = token.split(':', 2)
12
account = f"{username}:{password}"
13
14
# For all options see: https://github.com/ngrok/ngrok-py/blob/main/examples/ngrok-connect-full.py
15
if not options.get('authtoken_from_env'):
16
options['authtoken'] = token
17
if account:
18
options['basic_auth'] = account
19
if not options.get('session_metadata'):
20
options['session_metadata'] = 'stable-diffusion-webui'
21
22
23
try:
24
public_url = ngrok.connect(f"127.0.0.1:{port}", **options).url()
25
except Exception as e:
26
print(f'Invalid ngrok authtoken? ngrok connection aborted due to: {e}\n'
27
f'Your token: {token}, get the right one on https://dashboard.ngrok.com/get-started/your-authtoken')
28
else:
29
print(f'ngrok connected to localhost:{port}! URL: {public_url}\n'
30
'You can use this link after the launch is complete.')
31
32