Spaces:
Runtime error
Runtime error
Atri commited on
Commit ·
89ebfae
1
Parent(s): ce271a5
Add info block below image: backend, loaded models, live GPU/VRAM stats, weighting note
Browse files
app.py
CHANGED
|
@@ -164,6 +164,27 @@ model_management.load_models_gpu(
|
|
| 164 |
# --------------------------------------------------------------------------
|
| 165 |
import gradio as gr # noqa: E402 # needed for gr.Progress default arg below
|
| 166 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 167 |
|
| 168 |
@spaces.GPU(duration=int(os.environ.get("GPU_DURATION", "30")))
|
| 169 |
def generate_image(
|
|
@@ -181,7 +202,7 @@ def generate_image(
|
|
| 181 |
lora_name: str,
|
| 182 |
lora_strength: float,
|
| 183 |
progress: gr.Progress = gr.Progress(track_tqdm=False),
|
| 184 |
-
) -> np.ndarray:
|
| 185 |
width = max(512, min(1536, int(width) // 16 * 16))
|
| 186 |
height = max(512, min(1536, int(height) // 16 * 16))
|
| 187 |
seed = int(seed) if int(seed) >= 0 else random.randint(1, 2**63)
|
|
@@ -232,7 +253,7 @@ def generate_image(
|
|
| 232 |
progress(1, desc="Decoding")
|
| 233 |
decoded = vae_decode.decode(samples=sampled, vae=get_value_at_index(VAE, 0))
|
| 234 |
image = get_value_at_index(decoded, 0)[0]
|
| 235 |
-
|
| 236 |
torch.nan_to_num(image, nan=0.0, posinf=1.0, neginf=0.0)
|
| 237 |
.mul(255)
|
| 238 |
.clamp_(0, 255)
|
|
@@ -240,6 +261,12 @@ def generate_image(
|
|
| 240 |
.cpu()
|
| 241 |
.numpy()
|
| 242 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 243 |
|
| 244 |
|
| 245 |
# --------------------------------------------------------------------------
|
|
@@ -261,6 +288,7 @@ SCHEDULERS = ["simple", "normal", "karras", "exponential", "sgm_uniform"]
|
|
| 261 |
LORA_CHOICES = list_loras() or ["real_skin.safetensors"]
|
| 262 |
|
| 263 |
output_image = gr.Image(label="Generated Image")
|
|
|
|
| 264 |
|
| 265 |
with gr.Blocks(title="Anima Collection") as app:
|
| 266 |
with gr.Row():
|
|
@@ -290,6 +318,7 @@ with gr.Blocks(title="Anima Collection") as app:
|
|
| 290 |
|
| 291 |
with gr.Column(scale=1):
|
| 292 |
output_image.render()
|
|
|
|
| 293 |
|
| 294 |
resolution.change(
|
| 295 |
lambda name: list(RESOLUTIONS[name]),
|
|
@@ -303,7 +332,7 @@ with gr.Blocks(title="Anima Collection") as app:
|
|
| 303 |
steps_input, cfg_input, sampler_input, scheduler_input, lora_enable, lora_name_input,
|
| 304 |
lora_strength_input,
|
| 305 |
],
|
| 306 |
-
outputs=[output_image],
|
| 307 |
show_progress=True,
|
| 308 |
)
|
| 309 |
|
|
|
|
| 164 |
# --------------------------------------------------------------------------
|
| 165 |
import gradio as gr # noqa: E402 # needed for gr.Progress default arg below
|
| 166 |
|
| 167 |
+
BACKEND_INFO = (
|
| 168 |
+
"**Inference backend:** ComfyUI core (native Anima support, no custom nodes)\n"
|
| 169 |
+
"**Loaded models:** 4x Anima 2B checkpoints + Qwen-3 0.6B text encoder + Qwen-Image VAE (preloaded, ~18 GB)\n"
|
| 170 |
+
"**Prompt weighting:** supported, e.g. `(tag:1.2)`, `(tag)`, `[tag:0.8]` (per the Anima README, use higher weights than SDXL)"
|
| 171 |
+
)
|
| 172 |
+
|
| 173 |
+
|
| 174 |
+
# GPU stats are only real inside the ZeroGPU worker, so they are fetched at
|
| 175 |
+
# the end of each generation rather than at startup.
|
| 176 |
+
def gpu_stats() -> str:
|
| 177 |
+
try:
|
| 178 |
+
name = torch.cuda.get_device_name(0)
|
| 179 |
+
free, total = torch.cuda.mem_get_info(0)
|
| 180 |
+
used = total - free
|
| 181 |
+
except Exception as exc:
|
| 182 |
+
return f"**GPU:** unavailable ({exc})"
|
| 183 |
+
return (
|
| 184 |
+
f"**GPU:** {name}\n"
|
| 185 |
+
f"**VRAM:** {used / 1e9:.1f} GB used / {total / 1e9:.1f} GB total ({free / 1e9:.1f} GB free)"
|
| 186 |
+
)
|
| 187 |
+
|
| 188 |
|
| 189 |
@spaces.GPU(duration=int(os.environ.get("GPU_DURATION", "30")))
|
| 190 |
def generate_image(
|
|
|
|
| 202 |
lora_name: str,
|
| 203 |
lora_strength: float,
|
| 204 |
progress: gr.Progress = gr.Progress(track_tqdm=False),
|
| 205 |
+
) -> tuple[np.ndarray, str]:
|
| 206 |
width = max(512, min(1536, int(width) // 16 * 16))
|
| 207 |
height = max(512, min(1536, int(height) // 16 * 16))
|
| 208 |
seed = int(seed) if int(seed) >= 0 else random.randint(1, 2**63)
|
|
|
|
| 253 |
progress(1, desc="Decoding")
|
| 254 |
decoded = vae_decode.decode(samples=sampled, vae=get_value_at_index(VAE, 0))
|
| 255 |
image = get_value_at_index(decoded, 0)[0]
|
| 256 |
+
img_np = (
|
| 257 |
torch.nan_to_num(image, nan=0.0, posinf=1.0, neginf=0.0)
|
| 258 |
.mul(255)
|
| 259 |
.clamp_(0, 255)
|
|
|
|
| 261 |
.cpu()
|
| 262 |
.numpy()
|
| 263 |
)
|
| 264 |
+
info = (
|
| 265 |
+
BACKEND_INFO
|
| 266 |
+
+ f"\n{gpu_stats()}"
|
| 267 |
+
+ f"\n**Last run:** {model_name} | {width}x{height} | {steps} steps | CFG {cfg} | seed {seed}"
|
| 268 |
+
)
|
| 269 |
+
return img_np, info
|
| 270 |
|
| 271 |
|
| 272 |
# --------------------------------------------------------------------------
|
|
|
|
| 288 |
LORA_CHOICES = list_loras() or ["real_skin.safetensors"]
|
| 289 |
|
| 290 |
output_image = gr.Image(label="Generated Image")
|
| 291 |
+
info_output = gr.Markdown(BACKEND_INFO + "\n_Run a generation to see live GPU/VRAM stats._")
|
| 292 |
|
| 293 |
with gr.Blocks(title="Anima Collection") as app:
|
| 294 |
with gr.Row():
|
|
|
|
| 318 |
|
| 319 |
with gr.Column(scale=1):
|
| 320 |
output_image.render()
|
| 321 |
+
info_output.render()
|
| 322 |
|
| 323 |
resolution.change(
|
| 324 |
lambda name: list(RESOLUTIONS[name]),
|
|
|
|
| 332 |
steps_input, cfg_input, sampler_input, scheduler_input, lora_enable, lora_name_input,
|
| 333 |
lora_strength_input,
|
| 334 |
],
|
| 335 |
+
outputs=[output_image, info_output],
|
| 336 |
show_progress=True,
|
| 337 |
)
|
| 338 |
|