Upload 6 files
Browse files- README.md +25 -8
- app.py +24 -8
- requirements.txt +4 -3
README.md
CHANGED
|
@@ -1,14 +1,16 @@
|
|
| 1 |
---
|
| 2 |
-
title: Z-Image + Watermark Remover
|
| 3 |
emoji: 🎨
|
| 4 |
colorFrom: yellow
|
| 5 |
colorTo: purple
|
| 6 |
sdk: gradio
|
|
|
|
|
|
|
| 7 |
app_file: app.py
|
| 8 |
-
|
| 9 |
---
|
| 10 |
|
| 11 |
-
# Z-Image + Watermark Remover
|
| 12 |
|
| 13 |
Combined ZeroGPU Space:
|
| 14 |
|
|
@@ -18,11 +20,22 @@ Combined ZeroGPU Space:
|
|
| 18 |
- Video watermark removal
|
| 19 |
- Gradio API
|
| 20 |
|
| 21 |
-
##
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 22 |
|
| 23 |
### Florence-2 / Transformers compatibility
|
| 24 |
|
| 25 |
-
The runtime uses `transformers
|
| 26 |
|
| 27 |
The patch handles the `forced_bos_token_id` access used by older Florence-2 remote code.
|
| 28 |
|
|
@@ -50,8 +63,12 @@ The original audio stream is mapped back into the output when present.
|
|
| 50 |
- `remove_image`
|
| 51 |
- `remove_video`
|
| 52 |
|
| 53 |
-
##
|
| 54 |
|
| 55 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 56 |
|
| 57 |
-
|
|
|
|
| 1 |
---
|
| 2 |
+
title: Z-Image + Watermark Remover V4
|
| 3 |
emoji: 🎨
|
| 4 |
colorFrom: yellow
|
| 5 |
colorTo: purple
|
| 6 |
sdk: gradio
|
| 7 |
+
sdk_version: 5.23.1
|
| 8 |
+
python_version: "3.10"
|
| 9 |
app_file: app.py
|
| 10 |
+
startup_duration_timeout: 30m
|
| 11 |
---
|
| 12 |
|
| 13 |
+
# Z-Image + Watermark Remover V4
|
| 14 |
|
| 15 |
Combined ZeroGPU Space:
|
| 16 |
|
|
|
|
| 20 |
- Video watermark removal
|
| 21 |
- Gradio API
|
| 22 |
|
| 23 |
+
## V4 dependency fix
|
| 24 |
+
|
| 25 |
+
Gradio is **not** listed in `requirements.txt`. Hugging Face Spaces installs and manages Gradio from the `sdk_version` field above.
|
| 26 |
+
|
| 27 |
+
This avoids the dependency conflict between:
|
| 28 |
+
|
| 29 |
+
- Gradio 6.x -> `huggingface-hub >= 1.16`
|
| 30 |
+
- Transformers 4.56/4.57 -> `huggingface-hub < 1.0`
|
| 31 |
+
|
| 32 |
+
V4 uses Gradio 5.23.1 through the Space SDK and keeps `huggingface-hub < 1.0` for the Transformers/Florence-2 stack.
|
| 33 |
+
|
| 34 |
+
## V3 fixes retained
|
| 35 |
|
| 36 |
### Florence-2 / Transformers compatibility
|
| 37 |
|
| 38 |
+
The runtime uses `transformers==4.57.6` and applies a compatibility patch before loading Florence-2.
|
| 39 |
|
| 40 |
The patch handles the `forced_bos_token_id` access used by older Florence-2 remote code.
|
| 41 |
|
|
|
|
| 63 |
- `remove_image`
|
| 64 |
- `remove_video`
|
| 65 |
|
| 66 |
+
## Deployment
|
| 67 |
|
| 68 |
+
1. Create/select a Gradio Space.
|
| 69 |
+
2. Select ZeroGPU hardware.
|
| 70 |
+
3. Upload the files from this ZIP to the Space root.
|
| 71 |
+
4. If the Space has an older cached environment, use Factory Reboot after committing.
|
| 72 |
+
5. Optionally add `HF_TOKEN` as a Space Secret for authenticated Hub access.
|
| 73 |
|
| 74 |
+
Do not add `gradio`, `gradio-client`, `spaces`, or `huggingface-hub` to `requirements.txt`.
|
app.py
CHANGED
|
@@ -16,8 +16,11 @@ print("Z-Image pipeline loaded!")
|
|
| 16 |
from watermark import preview, remove_image, process_video
|
| 17 |
|
| 18 |
@spaces.GPU(duration=60)
|
| 19 |
-
def generate_image(prompt, height, width, steps
|
|
|
|
| 20 |
progress=gr.Progress(track_tqdm=True)):
|
|
|
|
|
|
|
| 21 |
if randomize_seed:
|
| 22 |
seed = torch.randint(0, 2**32 - 1, (1,)).item()
|
| 23 |
seed = int(seed)
|
|
@@ -33,21 +36,30 @@ def generate_image(prompt, height, width, steps, seed, randomize_seed,
|
|
| 33 |
return image, seed
|
| 34 |
|
| 35 |
@spaces.GPU(duration=60)
|
| 36 |
-
def wm_preview(image, detection_prompt="watermark",
|
|
|
|
|
|
|
|
|
|
| 37 |
return preview(image, float(max_bbox_percent), detection_prompt or "watermark")
|
| 38 |
|
| 39 |
@spaces.GPU(duration=90)
|
| 40 |
-
def wm_remove_image(image, detection_prompt="watermark",
|
| 41 |
-
max_bbox_percent=30,
|
|
|
|
|
|
|
|
|
|
| 42 |
return remove_image(
|
| 43 |
image, float(max_bbox_percent),
|
| 44 |
detection_prompt or "watermark", bool(transparent)
|
| 45 |
)
|
| 46 |
|
| 47 |
@spaces.GPU(duration=300)
|
| 48 |
-
def wm_remove_video(video_path, detection_prompt="watermark",
|
| 49 |
-
max_bbox_percent=30, detection_skip=5,
|
| 50 |
-
fade_in=2, fade_out=2,
|
|
|
|
|
|
|
|
|
|
| 51 |
if not video_path:
|
| 52 |
raise gr.Error("Please upload a video.")
|
| 53 |
return process_video(
|
|
@@ -145,4 +157,8 @@ with gr.Blocks(title="Z-Image + Watermark Remover V3") as demo:
|
|
| 145 |
)
|
| 146 |
|
| 147 |
if __name__ == "__main__":
|
| 148 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 16 |
from watermark import preview, remove_image, process_video
|
| 17 |
|
| 18 |
@spaces.GPU(duration=60)
|
| 19 |
+
def generate_image(prompt: str, height: int, width: int, steps: int,
|
| 20 |
+
seed: int, randomize_seed: bool,
|
| 21 |
progress=gr.Progress(track_tqdm=True)):
|
| 22 |
+
"""Generate an image with Z-Image-Turbo and return the image plus seed."""
|
| 23 |
+
|
| 24 |
if randomize_seed:
|
| 25 |
seed = torch.randint(0, 2**32 - 1, (1,)).item()
|
| 26 |
seed = int(seed)
|
|
|
|
| 36 |
return image, seed
|
| 37 |
|
| 38 |
@spaces.GPU(duration=60)
|
| 39 |
+
def wm_preview(image, detection_prompt: str = "watermark",
|
| 40 |
+
max_bbox_percent: float = 30):
|
| 41 |
+
"""Detect likely watermark regions and return a preview with boxes."""
|
| 42 |
+
|
| 43 |
return preview(image, float(max_bbox_percent), detection_prompt or "watermark")
|
| 44 |
|
| 45 |
@spaces.GPU(duration=90)
|
| 46 |
+
def wm_remove_image(image, detection_prompt: str = "watermark",
|
| 47 |
+
max_bbox_percent: float = 30,
|
| 48 |
+
transparent: bool = False):
|
| 49 |
+
"""Detect and remove watermark regions from an image."""
|
| 50 |
+
|
| 51 |
return remove_image(
|
| 52 |
image, float(max_bbox_percent),
|
| 53 |
detection_prompt or "watermark", bool(transparent)
|
| 54 |
)
|
| 55 |
|
| 56 |
@spaces.GPU(duration=300)
|
| 57 |
+
def wm_remove_video(video_path: str, detection_prompt: str = "watermark",
|
| 58 |
+
max_bbox_percent: float = 30, detection_skip: int = 5,
|
| 59 |
+
fade_in: int = 2, fade_out: int = 2,
|
| 60 |
+
progress=gr.Progress()):
|
| 61 |
+
"""Detect and remove watermarks from a video while preserving audio."""
|
| 62 |
+
|
| 63 |
if not video_path:
|
| 64 |
raise gr.Error("Please upload a video.")
|
| 65 |
return process_video(
|
|
|
|
| 157 |
)
|
| 158 |
|
| 159 |
if __name__ == "__main__":
|
| 160 |
+
print("Starting Gradio Space...")
|
| 161 |
+
print(f"CUDA available: {torch.cuda.is_available()}")
|
| 162 |
+
if torch.cuda.is_available():
|
| 163 |
+
print(f"CUDA device: {torch.cuda.get_device_name(torch.cuda.current_device())}")
|
| 164 |
+
demo.launch(server_name="0.0.0.0", server_port=7860)
|
requirements.txt
CHANGED
|
@@ -1,12 +1,13 @@
|
|
| 1 |
-
#
|
| 2 |
-
# Do
|
| 3 |
|
| 4 |
diffusers
|
| 5 |
-
transformers
|
| 6 |
accelerate
|
| 7 |
peft
|
| 8 |
safetensors
|
| 9 |
sentencepiece
|
|
|
|
| 10 |
|
| 11 |
opencv-python-headless>=4.8,<4.12
|
| 12 |
numpy<2
|
|
|
|
| 1 |
+
# Gradio, spaces, and huggingface_hub are platform-managed by Hugging Face Spaces.
|
| 2 |
+
# Do NOT add them here.
|
| 3 |
|
| 4 |
diffusers
|
| 5 |
+
transformers==4.57.6
|
| 6 |
accelerate
|
| 7 |
peft
|
| 8 |
safetensors
|
| 9 |
sentencepiece
|
| 10 |
+
huggingface-hub<1.0
|
| 11 |
|
| 12 |
opencv-python-headless>=4.8,<4.12
|
| 13 |
numpy<2
|