gmk123 commited on
Commit
ae180e7
·
verified ·
1 Parent(s): d41b412

Upload 3 files

Browse files
Files changed (3) hide show
  1. zorok.py +23 -0
  2. zrok.py +49 -0
  3. zrun.py +51 -0
zorok.py ADDED
@@ -0,0 +1,23 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ import subprocess
3
+
4
+ def zzz():
5
+ try:
6
+ zorok = "/home/studio-lab-user/.zrok/bin"
7
+ os.makedirs(zorok, exist_ok=True)
8
+ subprocess.run(["curl", "-sLO", "https://github.com/openziti/zrok/releases/download/v0.4.23/zrok_0.4.23_linux_amd64.tar.gz"], check=True)
9
+ subprocess.run(["tar", "-xzf", "zrok_0.4.23_linux_amd64.tar.gz", "-C", zorok, "--wildcards", "*zrok"], check=True)
10
+ os.remove("zrok_0.4.23_linux_amd64.tar.gz")
11
+ print("""
12
+ 现在,注册您的 ZROK 帐户。
13
+ 复制并粘贴此命令
14
+ ~/.zrok/bin/zrok invite
15
+ 进入终端 -- Terminal
16
+
17
+ 查看视频教程 https://youtu.be/prTD99GbWlQ
18
+ """)
19
+
20
+ except Exception as e:
21
+ print(f"An error occurred: {e}")
22
+
23
+ zzz()
zrok.py ADDED
@@ -0,0 +1,49 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from multiprocessing import Process, Queue
2
+ import subprocess
3
+ import sys
4
+ import re
5
+
6
+ def hitozuma(token, zrok_out):
7
+ try:
8
+ oppai = subprocess.run(['/home/studio-lab-user/.zrok/bin/zrok', 'enable', token],
9
+ check=False, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, text=True)
10
+
11
+ ass = subprocess.Popen(["/home/studio-lab-user/.zrok/bin/zrok", "share", "public", "localhost:7860", "--headless"],
12
+ stdout=subprocess.PIPE, stderr=subprocess.STDOUT, text=True)
13
+
14
+ urlp = re.compile(r'https?://[^\s]*\.zrok\.io')
15
+ asu = ("◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼◼")
16
+
17
+ if oppai.returncode == 0:
18
+ zrok_out.put(f"\n{asu}\n[ZROK] environment enabled.\n")
19
+
20
+ else:
21
+ if "enabled environment" in oppai.stdout:
22
+ zrok_out.put(f"\n{asu}\n[ZROK] environment already enabled.\n")
23
+ else:
24
+ zrok_out.put(oppai.stdout)
25
+
26
+ for line in ass.stdout:
27
+ urls = urlp.findall(line)
28
+ for url in urls:
29
+ zrok_out.put(f"[ZROK] {url}\n{asu}\n\n")
30
+
31
+ ass.wait()
32
+
33
+ except:
34
+ pass
35
+
36
+ if __name__ == '__main__':
37
+ if len(sys.argv) != 2:
38
+ sys.exit("")
39
+
40
+ zrok_out = Queue()
41
+
42
+ process = Process(target=hitozuma, args=(sys.argv[1], zrok_out))
43
+ process.start()
44
+
45
+ while process.is_alive() or not zrok_out.empty():
46
+ while not zrok_out.empty():
47
+ print(zrok_out.get(), end='', flush=True)
48
+
49
+ process.join()
zrun.py ADDED
@@ -0,0 +1,51 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import subprocess
2
+ import threading
3
+ import sys
4
+ import os
5
+
6
+ os.environ['LD_PRELOAD'] = '/home/studio-lab-user/.conda/envs/default/lib/libtcmalloc_minimal.so.4'
7
+
8
+ def zrok_launch(token, launch_args):
9
+
10
+ subprocess.run(
11
+ f"mkdir -p tmp_models /tmp/ControlNet",
12
+ shell=True,
13
+ stdout=subprocess.DEVNULL,
14
+ stderr=subprocess.DEVNULL)
15
+
16
+ try:
17
+ zrok_process = subprocess.Popen(['python', 'zrok.py', token], stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True)
18
+ launch_process = subprocess.Popen(['python', 'webui.py'] + launch_args,
19
+ stdout=sys.stdout, stderr=sys.stdout, text=True)
20
+
21
+ def capture_output(process):
22
+ try:
23
+ if process.stdout is not None:
24
+ for line in process.stdout:
25
+ print(line.strip())
26
+
27
+ except Exception:
28
+ pass
29
+
30
+ zrok_thread = threading.Thread(target=capture_output, args=(zrok_process,))
31
+ launch_thread = threading.Thread(target=capture_output, args=(launch_process,))
32
+
33
+ zrok_thread.start()
34
+ launch_thread.start()
35
+
36
+ zrok_thread.join()
37
+ launch_thread.join()
38
+
39
+ except KeyboardInterrupt:
40
+ pass
41
+
42
+ except Exception as e:
43
+ print("Error:", str(e))
44
+
45
+ if __name__ == "__main__":
46
+ if len(sys.argv) < 2:
47
+ sys.exit(1)
48
+
49
+ token = sys.argv[1]
50
+ launch_args = sys.argv[2:]
51
+ zrok_launch(token, launch_args)