Spaces:
Sleeping
Sleeping
Gradio SDK + n-Arno V1 Turbo AIO + CFG 1 + pre-built binary
Browse files- Dockerfile +0 -22
- README.md +3 -1
- app.py +44 -9
- requirements.txt +3 -0
Dockerfile
DELETED
|
@@ -1,22 +0,0 @@
|
|
| 1 |
-
FROM python:3.11-slim
|
| 2 |
-
|
| 3 |
-
RUN apt-get update && apt-get install -y --no-install-recommends \
|
| 4 |
-
git cmake build-essential && \
|
| 5 |
-
rm -rf /var/lib/apt/lists/*
|
| 6 |
-
|
| 7 |
-
RUN git clone --depth 1 --recurse-submodules https://github.com/leejet/stable-diffusion.cpp /tmp/sdcpp && \
|
| 8 |
-
cd /tmp/sdcpp && mkdir build && cd build && \
|
| 9 |
-
cmake .. -DCMAKE_BUILD_TYPE=Release \
|
| 10 |
-
-DSD_BUILD_SHARED_LIBS=OFF && \
|
| 11 |
-
cmake --build . --config Release -j1 && \
|
| 12 |
-
cp bin/sd-cli /usr/local/bin/sd-cli && \
|
| 13 |
-
rm -rf /tmp/sdcpp
|
| 14 |
-
|
| 15 |
-
RUN pip install --no-cache-dir "gradio[mcp]" Pillow huggingface-hub
|
| 16 |
-
|
| 17 |
-
WORKDIR /app
|
| 18 |
-
COPY app.py .
|
| 19 |
-
COPY README.md .
|
| 20 |
-
|
| 21 |
-
EXPOSE 7860
|
| 22 |
-
CMD ["python", "app.py"]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
README.md
CHANGED
|
@@ -3,7 +3,9 @@ title: Anima Base v1.0 CPU
|
|
| 3 |
emoji: 🎨
|
| 4 |
colorFrom: indigo
|
| 5 |
colorTo: red
|
| 6 |
-
sdk:
|
|
|
|
|
|
|
| 7 |
pinned: false
|
| 8 |
license: other
|
| 9 |
short_description: Anime image generation with Anima Base v1.0 on CPU
|
|
|
|
| 3 |
emoji: 🎨
|
| 4 |
colorFrom: indigo
|
| 5 |
colorTo: red
|
| 6 |
+
sdk: gradio
|
| 7 |
+
sdk_version: 6.14.0
|
| 8 |
+
app_file: app.py
|
| 9 |
pinned: false
|
| 10 |
license: other
|
| 11 |
short_description: Anime image generation with Anima Base v1.0 on CPU
|
app.py
CHANGED
|
@@ -31,13 +31,47 @@ def _ensure_file(repo_id, filename, dest_dir):
|
|
| 31 |
return hf_hub_download(repo_id=repo_id, filename=filename, local_dir=dest_dir)
|
| 32 |
|
| 33 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 34 |
def _ensure_sdcli():
|
| 35 |
-
"""Find sd-cli in PATH
|
| 36 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 37 |
if candidate and os.path.isfile(candidate):
|
| 38 |
return candidate
|
| 39 |
-
|
| 40 |
-
sys.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 41 |
|
| 42 |
|
| 43 |
SDCLI_PATH = None
|
|
@@ -50,7 +84,7 @@ _proc_lock = threading.Lock()
|
|
| 50 |
DEFAULT_NEGATIVE = "worst quality, low quality, score_1, score_2, score_3, artist name"
|
| 51 |
DEFAULT_RESOLUTION = "512x512"
|
| 52 |
RESOLUTIONS = ["512x512", "768x512", "512x768"]
|
| 53 |
-
CFG =
|
| 54 |
SAMPLER = "er_sde"
|
| 55 |
SCHEDULER = "smoothstep"
|
| 56 |
DEFAULT_STEPS = 8
|
|
@@ -112,6 +146,7 @@ def _run_sdcli(cmd, timeout=TIMEOUT):
|
|
| 112 |
global _active_t0, _user_killed
|
| 113 |
env = os.environ.copy()
|
| 114 |
env.update(_CHILD_ENV_OVERRIDES)
|
|
|
|
| 115 |
_trim_process_memory()
|
| 116 |
|
| 117 |
# Disk-backed logs avoid growing the Gradio host RSS throughout a long verbose run.
|
|
@@ -266,7 +301,7 @@ def _init_models():
|
|
| 266 |
print("[init] Ensuring AIO GGUF model file...")
|
| 267 |
t0 = time.time()
|
| 268 |
aio_path = _ensure_file(
|
| 269 |
-
"
|
| 270 |
MODELS_DIR,
|
| 271 |
)
|
| 272 |
print(f"[init] Model ready in {time.time()-t0:.1f}s")
|
|
@@ -303,9 +338,9 @@ def main():
|
|
| 303 |
analytics_enabled=False,
|
| 304 |
) as demo:
|
| 305 |
gr.Markdown(
|
| 306 |
-
"**[Anima
|
| 307 |
-
"(
|
| 308 |
-
"+ [
|
| 309 |
"via [sd.cpp](https://github.com/leejet/stable-diffusion.cpp) | "
|
| 310 |
f"CFG {CFG}, {SAMPLER} | CPU ~15m @512x512"
|
| 311 |
)
|
|
|
|
| 31 |
return hf_hub_download(repo_id=repo_id, filename=filename, local_dir=dest_dir)
|
| 32 |
|
| 33 |
|
| 34 |
+
BIN_DIR = os.environ.get("ANIMA_BIN_DIR", "/tmp/anima_bin")
|
| 35 |
+
os.makedirs(BIN_DIR, exist_ok=True)
|
| 36 |
+
|
| 37 |
+
SDCLI_RELEASE_URL = (
|
| 38 |
+
"https://github.com/leejet/stable-diffusion.cpp/releases/download/"
|
| 39 |
+
"master-615-67dda3f/sd-master-67dda3f-bin-Linux-Ubuntu-24.04-x86_64.zip"
|
| 40 |
+
)
|
| 41 |
+
|
| 42 |
+
|
| 43 |
def _ensure_sdcli():
|
| 44 |
+
"""Find sd-cli in PATH or download pre-built binary."""
|
| 45 |
+
import zipfile, stat
|
| 46 |
+
for candidate in [
|
| 47 |
+
os.path.join(BIN_DIR, "sd-cli"),
|
| 48 |
+
shutil.which("sd-cli"),
|
| 49 |
+
shutil.which("sd-cli.exe"),
|
| 50 |
+
]:
|
| 51 |
if candidate and os.path.isfile(candidate):
|
| 52 |
return candidate
|
| 53 |
+
|
| 54 |
+
if sys.platform == "win32":
|
| 55 |
+
print("[init] sd-cli not in PATH. Build stable-diffusion.cpp from source.")
|
| 56 |
+
sys.exit(1)
|
| 57 |
+
|
| 58 |
+
print("[init] Downloading pre-built sd-cli...")
|
| 59 |
+
zip_path = os.path.join(BIN_DIR, "sdcli.zip")
|
| 60 |
+
subprocess.run(["curl", "-sL", "-o", zip_path, SDCLI_RELEASE_URL], check=True)
|
| 61 |
+
with zipfile.ZipFile(zip_path) as zf:
|
| 62 |
+
for name in zf.namelist():
|
| 63 |
+
basename = os.path.basename(name)
|
| 64 |
+
if basename in ("sd-cli", "libstable-diffusion.so"):
|
| 65 |
+
dest = os.path.join(BIN_DIR, basename)
|
| 66 |
+
with zf.open(name) as src, open(dest, "wb") as dst:
|
| 67 |
+
shutil.copyfileobj(src, dst)
|
| 68 |
+
os.chmod(dest, os.stat(dest).st_mode | stat.S_IEXEC)
|
| 69 |
+
os.remove(zip_path)
|
| 70 |
+
cli_path = os.path.join(BIN_DIR, "sd-cli")
|
| 71 |
+
if not os.path.isfile(cli_path):
|
| 72 |
+
raise RuntimeError("sd-cli not found in release zip")
|
| 73 |
+
print(f"[init] sd-cli ready at {cli_path}")
|
| 74 |
+
return cli_path
|
| 75 |
|
| 76 |
|
| 77 |
SDCLI_PATH = None
|
|
|
|
| 84 |
DEFAULT_NEGATIVE = "worst quality, low quality, score_1, score_2, score_3, artist name"
|
| 85 |
DEFAULT_RESOLUTION = "512x512"
|
| 86 |
RESOLUTIONS = ["512x512", "768x512", "512x768"]
|
| 87 |
+
CFG = 1.0
|
| 88 |
SAMPLER = "er_sde"
|
| 89 |
SCHEDULER = "smoothstep"
|
| 90 |
DEFAULT_STEPS = 8
|
|
|
|
| 146 |
global _active_t0, _user_killed
|
| 147 |
env = os.environ.copy()
|
| 148 |
env.update(_CHILD_ENV_OVERRIDES)
|
| 149 |
+
env["LD_LIBRARY_PATH"] = BIN_DIR + ":" + env.get("LD_LIBRARY_PATH", "")
|
| 150 |
_trim_process_memory()
|
| 151 |
|
| 152 |
# Disk-backed logs avoid growing the Gradio host RSS throughout a long verbose run.
|
|
|
|
| 301 |
print("[init] Ensuring AIO GGUF model file...")
|
| 302 |
t0 = time.time()
|
| 303 |
aio_path = _ensure_file(
|
| 304 |
+
"n-Arno/Anima-P3-Turbo-AIO-Q4_K", "Anima-V1-Turbo-AIO-Q4_K.gguf",
|
| 305 |
MODELS_DIR,
|
| 306 |
)
|
| 307 |
print(f"[init] Model ready in {time.time()-t0:.1f}s")
|
|
|
|
| 338 |
analytics_enabled=False,
|
| 339 |
) as demo:
|
| 340 |
gr.Markdown(
|
| 341 |
+
"**[Anima V1 Turbo AIO Q4_K](https://huggingface.co/n-Arno/Anima-P3-Turbo-AIO-Q4_K)** GGUF "
|
| 342 |
+
"([DiT anima-base-v1.0](https://huggingface.co/circlestone-labs/Anima) "
|
| 343 |
+
"+ [DMD2 Turbo](https://civitai.red/models/2619830) + abliterated TE) "
|
| 344 |
"via [sd.cpp](https://github.com/leejet/stable-diffusion.cpp) | "
|
| 345 |
f"CFG {CFG}, {SAMPLER} | CPU ~15m @512x512"
|
| 346 |
)
|
requirements.txt
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
gradio[mcp]
|
| 2 |
+
Pillow
|
| 3 |
+
huggingface-hub
|