Spaces:
Sleeping
Sleeping
File size: 1,290 Bytes
a131bde |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
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)))
|