Spaces:
Sleeping
Sleeping
Fix: transformers 5.x compat, gradio 6.x, ensure_weights, sam3 access
Browse files- Remove show_api (removed in gradio 6.x)
- Add FLAX_WEIGHTS_NAME compat patch for transformers 5.x
- Add safety_checker=None to bypass Sam3 load error
- Add ensure_weights() with sentinel-file skip logic + retry
- Add hf_transfer for faster downloads
- Update requirements: transformers>=5.3.0, add av/moviepy/peft
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
- diffueraser/diffueraser.py +2 -1
- gradio_app.py +38 -7
- requirements.txt +2 -1
diffueraser/diffueraser.py
CHANGED
|
@@ -210,7 +210,8 @@ class DiffuEraser:
|
|
| 210 |
text_encoder=self.text_encoder,
|
| 211 |
tokenizer=self.tokenizer,
|
| 212 |
unet=self.unet_main,
|
| 213 |
-
brushnet=self.brushnet
|
|
|
|
| 214 |
).to(self.device, torch.float16)
|
| 215 |
self.pipeline.scheduler = UniPCMultistepScheduler.from_config(self.pipeline.scheduler.config)
|
| 216 |
self.pipeline.set_progress_bar_config(disable=True)
|
|
|
|
| 210 |
text_encoder=self.text_encoder,
|
| 211 |
tokenizer=self.tokenizer,
|
| 212 |
unet=self.unet_main,
|
| 213 |
+
brushnet=self.brushnet,
|
| 214 |
+
safety_checker=None,
|
| 215 |
).to(self.device, torch.float16)
|
| 216 |
self.pipeline.scheduler = UniPCMultistepScheduler.from_config(self.pipeline.scheduler.config)
|
| 217 |
self.pipeline.set_progress_bar_config(disable=True)
|
gradio_app.py
CHANGED
|
@@ -1,5 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import spaces
|
| 2 |
-
import torch,
|
| 3 |
from PIL import Image
|
| 4 |
import gradio as gr
|
| 5 |
from huggingface_hub import snapshot_download
|
|
@@ -9,13 +12,41 @@ import transformers.utils
|
|
| 9 |
if not hasattr(transformers.utils, "FLAX_WEIGHTS_NAME"):
|
| 10 |
transformers.utils.FLAX_WEIGHTS_NAME = "flax_model.msgpack"
|
| 11 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 12 |
for subfolder in ["diffuEraser","stable-diffusion-v1-5","PCM_Weights","propainter","sd-vae-ft-mse"]:
|
| 13 |
os.makedirs(os.path.join("weights", subfolder), exist_ok=True)
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 19 |
|
| 20 |
from diffueraser.diffueraser import DiffuEraser
|
| 21 |
from propainter.inference import Propainter, get_device
|
|
@@ -171,4 +202,4 @@ with gr.Blocks(title="DiffuEraser + SAM3 Watermark Remover") as demo:
|
|
| 171 |
inputs=[input_video, text_prompt])
|
| 172 |
submit_btn.click(fn=infer, inputs=[input_video, text_prompt], outputs=[video_result])
|
| 173 |
|
| 174 |
-
demo.queue().launch(
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
os.environ.setdefault("HF_HUB_DISABLE_SYMLINKS_WARNING", "1")
|
| 3 |
+
os.environ.setdefault("HF_HUB_ENABLE_HF_TRANSFER", "1")
|
| 4 |
import spaces
|
| 5 |
+
import torch, time, datetime, numpy as np, cv2
|
| 6 |
from PIL import Image
|
| 7 |
import gradio as gr
|
| 8 |
from huggingface_hub import snapshot_download
|
|
|
|
| 12 |
if not hasattr(transformers.utils, "FLAX_WEIGHTS_NAME"):
|
| 13 |
transformers.utils.FLAX_WEIGHTS_NAME = "flax_model.msgpack"
|
| 14 |
|
| 15 |
+
def ensure_weights(repo_id, local_dir, sentinel_files, ignore_patterns=None, max_retries=5):
|
| 16 |
+
"""Download repo only if sentinel files are missing; retry on network errors."""
|
| 17 |
+
import time as _time
|
| 18 |
+
# Check if already downloaded by verifying sentinel files exist
|
| 19 |
+
if all(os.path.exists(os.path.join(local_dir, f)) for f in sentinel_files):
|
| 20 |
+
print(f"[Skip] {repo_id} already present at {local_dir}")
|
| 21 |
+
return
|
| 22 |
+
os.makedirs(local_dir, exist_ok=True)
|
| 23 |
+
for attempt in range(1, max_retries + 1):
|
| 24 |
+
try:
|
| 25 |
+
snapshot_download(repo_id=repo_id, local_dir=local_dir,
|
| 26 |
+
ignore_patterns=ignore_patterns)
|
| 27 |
+
print(f"[OK] {repo_id}")
|
| 28 |
+
return
|
| 29 |
+
except Exception as e:
|
| 30 |
+
if attempt == max_retries:
|
| 31 |
+
raise
|
| 32 |
+
print(f"[Download] {repo_id} attempt {attempt} failed: {e}\n Retrying in 5s...")
|
| 33 |
+
_time.sleep(5)
|
| 34 |
+
|
| 35 |
for subfolder in ["diffuEraser","stable-diffusion-v1-5","PCM_Weights","propainter","sd-vae-ft-mse"]:
|
| 36 |
os.makedirs(os.path.join("weights", subfolder), exist_ok=True)
|
| 37 |
+
|
| 38 |
+
ensure_weights("lixiaowen/diffuEraser", "./weights/diffuEraser",
|
| 39 |
+
sentinel_files=["brushnet/diffusion_pytorch_model.safetensors",
|
| 40 |
+
"unet_main/diffusion_pytorch_model.safetensors"])
|
| 41 |
+
ensure_weights("stable-diffusion-v1-5/stable-diffusion-v1-5", "./weights/stable-diffusion-v1-5",
|
| 42 |
+
sentinel_files=["unet/diffusion_pytorch_model.safetensors", "model_index.json"],
|
| 43 |
+
ignore_patterns=["*.ckpt", "*.msgpack", "*non_ema*", "*.pb", "*.h5", "flax_*"])
|
| 44 |
+
ensure_weights("wangfuyun/PCM_Weights", "./weights/PCM_Weights",
|
| 45 |
+
sentinel_files=["sd15/pcm_sd15_smallcfg_2step_converted.safetensors"])
|
| 46 |
+
ensure_weights("camenduru/ProPainter", "./weights/propainter",
|
| 47 |
+
sentinel_files=["ProPainter.pth"])
|
| 48 |
+
ensure_weights("stabilityai/sd-vae-ft-mse", "./weights/sd-vae-ft-mse",
|
| 49 |
+
sentinel_files=["diffusion_pytorch_model.safetensors"])
|
| 50 |
|
| 51 |
from diffueraser.diffueraser import DiffuEraser
|
| 52 |
from propainter.inference import Propainter, get_device
|
|
|
|
| 202 |
inputs=[input_video, text_prompt])
|
| 203 |
submit_btn.click(fn=infer, inputs=[input_video, text_prompt], outputs=[video_result])
|
| 204 |
|
| 205 |
+
demo.queue().launch(show_error=True, ssr_mode=False)
|
requirements.txt
CHANGED
|
@@ -1,7 +1,7 @@
|
|
| 1 |
torch==2.5.1
|
| 2 |
torchvision==0.20.1
|
| 3 |
torchaudio==2.5.1
|
| 4 |
-
transformers>=
|
| 5 |
diffusers==0.29.2
|
| 6 |
peft==0.13.2
|
| 7 |
accelerate>=0.25.0
|
|
@@ -17,5 +17,6 @@ tqdm==4.66.4
|
|
| 17 |
einops==0.8.0
|
| 18 |
scipy==1.13.1
|
| 19 |
huggingface-hub
|
|
|
|
| 20 |
urllib3==2.2.2
|
| 21 |
zipp==3.19.2
|
|
|
|
| 1 |
torch==2.5.1
|
| 2 |
torchvision==0.20.1
|
| 3 |
torchaudio==2.5.1
|
| 4 |
+
transformers>=5.3.0
|
| 5 |
diffusers==0.29.2
|
| 6 |
peft==0.13.2
|
| 7 |
accelerate>=0.25.0
|
|
|
|
| 17 |
einops==0.8.0
|
| 18 |
scipy==1.13.1
|
| 19 |
huggingface-hub
|
| 20 |
+
hf_transfer
|
| 21 |
urllib3==2.2.2
|
| 22 |
zipp==3.19.2
|