Spaces:
Sleeping
Sleeping
| import os | |
| import subprocess | |
| import threading | |
| import gradio as gr | |
| # ------------------------------- | |
| # 1️⃣ Install dependencies | |
| # ------------------------------- | |
| subprocess.run(["pip", "install", "-r", "requirements.txt"]) | |
| # ------------------------------- | |
| # 2️⃣ Function to start WebUI | |
| # ------------------------------- | |
| def start_webui(): | |
| """Launch Automatic1111 WebUI in background thread.""" | |
| # Set command-line args for WebUI | |
| os.environ["COMMANDLINE_ARGS"] = "--listen --xformers --enable-insecure-extension-access --medvram" | |
| # Launch WebUI | |
| subprocess.run(["python", "launch.py"]) | |
| # Run WebUI in a separate thread so Gradio stays alive | |
| threading.Thread(target=start_webui, daemon=True).start() | |
| # ------------------------------- | |
| # 3️⃣ Minimal Gradio interface | |
| # ------------------------------- | |
| def status(): | |
| return "✅ WebUI is running in the background." | |
| # Gradio app — one output textbox to keep Space alive | |
| with gr.Blocks() as demo: | |
| gr.Markdown("### Automatic1111 WebUI Launcher") | |
| gr.Button("Check status").click(status, outputs=[gr.Textbox()]) | |
| # ------------------------------- | |
| # 4️⃣ Launch Gradio (HF-friendly) | |
| # ------------------------------- | |
| demo.launch(server_name="0.0.0.0", server_port=int(os.environ.get("PORT", 7860))) | |