kg-09 commited on
Commit
6c411e4
1 Parent(s): a94ab52

Upload webui_comfy.py

Browse files
Files changed (1) hide show
  1. webui_comfy.py +35 -0
webui_comfy.py ADDED
@@ -0,0 +1,35 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import subprocess
2
+ import threading
3
+ import time
4
+ import socket
5
+ import urllib.request
6
+ import os
7
+
8
+ def install_cloudflared():
9
+ if not os.path.exists("cloudflared-linux-amd64.deb"):
10
+ subprocess.run(["wget", "https://github.com/cloudflare/cloudflared/releases/latest/download/cloudflared-linux-amd64.deb"])
11
+ subprocess.run(["dpkg", "-i", "cloudflared-linux-amd64.deb"])
12
+
13
+ def iframe_thread(port):
14
+ while True:
15
+ time.sleep(0.5)
16
+ sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
17
+ result = sock.connect_ex(('127.0.0.1', port))
18
+ if result == 0:
19
+ break
20
+ sock.close()
21
+ print("\nComfyUI finished loading, trying to launch cloudflared (if it gets stuck here cloudflared is having issues)\n")
22
+
23
+ p = subprocess.Popen(["cloudflared", "tunnel", "--url", "http://127.0.0.1:{}".format(port)], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
24
+ for line in p.stderr:
25
+ l = line.decode()
26
+ if "trycloudflare.com " in l:
27
+ print("This is the URL to access ComfyUI:", l[l.find("http"):], end='')
28
+
29
+ def main():
30
+ install_cloudflared()
31
+ threading.Thread(target=iframe_thread, daemon=True, args=(8188,)).start()
32
+ subprocess.run(["python", "main.py", "--port", "8188", "--auto-launch"])
33
+
34
+ if __name__ == "__main__":
35
+ main()