Nathyboy commited on
Commit
a131bde
·
verified ·
1 Parent(s): 1bf35fa

Update launch.py

Browse files
Files changed (1) hide show
  1. launch.py +39 -48
launch.py CHANGED
@@ -1,48 +1,39 @@
1
- from modules import launch_utils
2
-
3
- args = launch_utils.args
4
- python = launch_utils.python
5
- git = launch_utils.git
6
- index_url = launch_utils.index_url
7
- dir_repos = launch_utils.dir_repos
8
-
9
- commit_hash = launch_utils.commit_hash
10
- git_tag = launch_utils.git_tag
11
-
12
- run = launch_utils.run
13
- is_installed = launch_utils.is_installed
14
- repo_dir = launch_utils.repo_dir
15
-
16
- run_pip = launch_utils.run_pip
17
- check_run_python = launch_utils.check_run_python
18
- git_clone = launch_utils.git_clone
19
- git_pull_recursive = launch_utils.git_pull_recursive
20
- list_extensions = launch_utils.list_extensions
21
- run_extension_installer = launch_utils.run_extension_installer
22
- prepare_environment = launch_utils.prepare_environment
23
- configure_for_tests = launch_utils.configure_for_tests
24
- start = launch_utils.start
25
-
26
-
27
- def main():
28
- if args.dump_sysinfo:
29
- filename = launch_utils.dump_sysinfo()
30
-
31
- print(f"Sysinfo saved as {filename}. Exiting...")
32
-
33
- exit(0)
34
-
35
- launch_utils.startup_timer.record("initial startup")
36
-
37
- with launch_utils.startup_timer.subcategory("prepare environment"):
38
- if not args.skip_prepare_environment:
39
- prepare_environment()
40
-
41
- if args.test_server:
42
- configure_for_tests()
43
-
44
- start()
45
-
46
-
47
- if __name__ == "__main__":
48
- main()
 
1
+ import os
2
+ import subprocess
3
+ import threading
4
+ import gradio as gr
5
+
6
+ # -------------------------------
7
+ # 1️⃣ Install dependencies
8
+ # -------------------------------
9
+ subprocess.run(["pip", "install", "-r", "requirements.txt"])
10
+
11
+ # -------------------------------
12
+ # 2️⃣ Function to start WebUI
13
+ # -------------------------------
14
+ def start_webui():
15
+ """Launch Automatic1111 WebUI in background thread."""
16
+ # Set command-line args for WebUI
17
+ os.environ["COMMANDLINE_ARGS"] = "--listen --xformers --enable-insecure-extension-access --medvram"
18
+
19
+ # Launch WebUI
20
+ subprocess.run(["python", "launch.py"])
21
+
22
+ # Run WebUI in a separate thread so Gradio stays alive
23
+ threading.Thread(target=start_webui, daemon=True).start()
24
+
25
+ # -------------------------------
26
+ # 3️⃣ Minimal Gradio interface
27
+ # -------------------------------
28
+ def status():
29
+ return "✅ WebUI is running in the background."
30
+
31
+ # Gradio app one output textbox to keep Space alive
32
+ with gr.Blocks() as demo:
33
+ gr.Markdown("### Automatic1111 WebUI Launcher")
34
+ gr.Button("Check status").click(status, outputs=[gr.Textbox()])
35
+
36
+ # -------------------------------
37
+ # 4️⃣ Launch Gradio (HF-friendly)
38
+ # -------------------------------
39
+ demo.launch(server_name="0.0.0.0", server_port=int(os.environ.get("PORT", 7860)))