Skip to content

Instantly share code, notes, and snippets.

@yak1ex
Last active April 28, 2024 17:44
Show Gist options
  • Save yak1ex/0fd31b35996c722841efbb739b131d16 to your computer and use it in GitHub Desktop.
Save yak1ex/0fd31b35996c722841efbb739b131d16 to your computer and use it in GitHub Desktop.
A patch to use cloudflare for Fooocus tunneling, instead of gradio, in order to avoid server problem.
Based on https://github.com/lllyasviel/Fooocus/issues/2817#issuecomment-2080462056
diff --git a/webui.py b/webui.py
index 98780bf..5b87030 100644
--- a/webui.py
+++ b/webui.py
@@ -713,12 +713,36 @@ def dump_default_english_config():
# dump_default_english_config()
+### Injected for cloudflare
+# https://github.com/lllyasviel/Fooocus/issues/2817#issuecomment-2080462056
+import subprocess
+import threading
+import time
+import socket
+
+def iframe_thread(port):
+ while True:
+ time.sleep(0.5)
+ sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
+ result = sock.connect_ex(('127.0.0.1', port))
+ if result == 0:
+ break
+ sock.close()
+ print("\nFooocus finished loading, trying to launch cloudflared (if it gets stuck here cloudflared is having issues)\n")
+ p = subprocess.Popen(["cloudflared", "tunnel", "--url", "http://127.0.0.1:{}".format(port)], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
+ for line in p.stderr:
+ l = line.decode()
+ if "trycloudflare.com" in l:
+ print("This is the URL to access Fooocus:", l[l.find("https"):], end='')
+
+port = 7865 # Replace with the port number used by Fooocus
+threading.Thread(target=iframe_thread, daemon=True, args=(port,)).start()
+### Injected for cloudflare
+
shared.gradio_root.launch(
inbrowser=args_manager.args.in_browser,
server_name=args_manager.args.listen,
server_port=args_manager.args.port,
- share=args_manager.args.share,
- auth=check_auth if (args_manager.args.share or args_manager.args.listen) and auth_enabled else None,
allowed_paths=[modules.config.path_outputs],
blocked_paths=[constants.AUTH_FILENAME]
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment