Add initial implementation for Stable Diffusion A1111 web UI in CPU mode
Browse files- app.py +47 -0
- requirements.txt +0 -0
- space.yaml +4 -0
app.py
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
import subprocess
|
| 3 |
+
import gradio as gr
|
| 4 |
+
|
| 5 |
+
# Clone A1111 Web UI only if not already cloned
|
| 6 |
+
if not os.path.exists("stable-diffusion-webui"):
|
| 7 |
+
subprocess.run(
|
| 8 |
+
["git", "clone", "https://github.com/AUTOMATIC1111/stable-diffusion-webui.git"],
|
| 9 |
+
check=True,
|
| 10 |
+
)
|
| 11 |
+
|
| 12 |
+
os.chdir("stable-diffusion-webui")
|
| 13 |
+
|
| 14 |
+
# Install necessary dependencies
|
| 15 |
+
subprocess.run(["pip", "install", "-r", "requirements.txt"], check=True)
|
| 16 |
+
|
| 17 |
+
# Ensure CPU mode is enabled
|
| 18 |
+
os.environ["CUDA_VISIBLE_DEVICES"] = "-1"
|
| 19 |
+
|
| 20 |
+
# Download a smaller SD model to fit CPU constraints (e.g., SD 1.5 EMA-only)
|
| 21 |
+
MODEL_PATH = "models/Stable-diffusion/sd-v1-5-ema.ckpt"
|
| 22 |
+
MODEL_NAME = "sd-v1-5-ema.ckpt"
|
| 23 |
+
MODEL_API = "https://civitai.com/api/download/models/11745?type=Model&format=SafeTensor&size=full&fp=fp16"
|
| 24 |
+
if not os.path.exists(MODEL_PATH):
|
| 25 |
+
os.makedirs("models/Stable-diffusion", exist_ok=True)
|
| 26 |
+
subprocess.run(
|
| 27 |
+
["wget", "-O", MODEL_PATH, MODEL_API],
|
| 28 |
+
check=True,
|
| 29 |
+
)
|
| 30 |
+
|
| 31 |
+
|
| 32 |
+
# Launch web UI with CPU mode
|
| 33 |
+
def launch_webui():
|
| 34 |
+
os.system(
|
| 35 |
+
"python webui.py --listen --share --no-half --precision full --disable-nan-check --use-cpu all --skip-torch-cuda-test"
|
| 36 |
+
)
|
| 37 |
+
|
| 38 |
+
|
| 39 |
+
# Create a simple Gradio interface
|
| 40 |
+
def start():
|
| 41 |
+
return (
|
| 42 |
+
"Stable Diffusion A1111 (CPU Mode) is running! Click the link to open the UI."
|
| 43 |
+
)
|
| 44 |
+
|
| 45 |
+
|
| 46 |
+
interface = gr.Interface(fn=start, inputs=[], outputs="text")
|
| 47 |
+
interface.launch()
|
requirements.txt
ADDED
|
File without changes
|
space.yaml
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
sdk: gradio
|
| 2 |
+
app_file: app.py
|
| 3 |
+
python_version: 3.10
|
| 4 |
+
accelerator: cpu
|