Kontext-Watermark-Remover
The Kontext-Watermark-Remover is an adapter for black-forest-lab's FLUX.1-Kontext-dev, designed to precisely remove watermarks and textual content from images while maintaining the original image quality and context. The model was trained on 150 image pairs (75 start images and 75 end images) to ensure accurate and artifact-free watermark removal.
[photo content], remove any watermark text or logos from the image while preserving the background, texture, lighting, and overall realism. Ensure the edited areas blend seamlessly with surrounding details, leaving no visible traces of watermark removal.
Sample Inferences : Demo
|
|
|
|
|
|
|
|
|
|
Quick start with diffusers🧨
Required Packages
!pip install diffusers torch gradio transformers
!pip install pillow gradio-imageslider huggingface_hub
!pip install sentencepiece spaces peft torchvision accelerate
Run Demo
import os
import gradio as gr
import numpy as np
import spaces
import torch
import random
from PIL import Image
from typing import Iterable
from diffusers import FluxKontextPipeline
from diffusers.utils import load_image
from huggingface_hub import hf_hub_download
from gradio_imageslider import ImageSlider
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
# --- Main Model Initialization ---
MAX_SEED = np.iinfo(np.int32).max
pipe = FluxKontextPipeline.from_pretrained("black-forest-labs/FLUX.1-Kontext-dev", torch_dtype=torch.bfloat16).to("cuda")
# --- Load New Adapter ---
pipe.load_lora_weights("prithivMLmods/Kontext-Watermark-Remover", weight_name="Kontext-Watermark-Remover.safetensors", adapter_name="watermark_remover")
@spaces.GPU
def infer(input_image, prompt, seed=42, randomize_seed=False, guidance_scale=2.5, steps=28, progress=gr.Progress(track_tqdm=True)):
"""
Perform image editing, returning a pair for the ImageSlider.
"""
if not input_image:
raise gr.Error("Please upload an image for editing.")
pipe.set_adapters(["watermark_remover"], adapter_weights=[1.0])
if randomize_seed:
seed = random.randint(0, MAX_SEED)
original_image = input_image.copy().convert("RGB")
image = pipe(
image=original_image,
prompt=prompt,
guidance_scale=guidance_scale,
width = original_image.size[0],
height = original_image.size[1],
num_inference_steps=steps,
generator=torch.Generator().manual_seed(seed),
).images[0]
return (original_image, image), seed, gr.Button(visible=True)
css="""
#col-container {
margin: 0 auto;
max-width: 960px;
}
#main-title h1 {font-size: 2.1em !important;}
"""
with gr.Blocks(css=css) as demo:
with gr.Column(elem_id="col-container"):
gr.Markdown("# **Photo-Mate-i2i: Watermark Remover**", elem_id="main-title")
gr.Markdown("Image manipulation with FLUX.1 Kontext. This demo focuses on watermark removal.")
with gr.Row():
with gr.Column():
input_image = gr.Image(label="Upload Image with Watermark", type="pil", height="300")
with gr.Row():
prompt = gr.Text(
label="Edit Prompt",
show_label=False,
max_lines=1,
placeholder="e.g., 'Remove the watermark'",
container=False,
value="[photo content], remove any watermark text or logos from the image while preserving the background, texture, lighting, and overall realism. Ensure the edited areas blend seamlessly with surrounding details, leaving no visible traces of watermark removal."
)
run_button = gr.Button("Run", variant="primary", scale=0)
with gr.Accordion("Advanced Settings", open=False):
seed = gr.Slider(
label="Seed",
minimum=0,
maximum=MAX_SEED,
step=1,
value=0,
)
randomize_seed = gr.Checkbox(label="Randomize seed", value=True)
guidance_scale = gr.Slider(
label="Guidance Scale",
minimum=1,
maximum=10,
step=0.1,
value=2.5,
)
steps = gr.Slider(
label="Steps",
minimum=1,
maximum=30,
value=28,
step=1
)
with gr.Column():
output_slider = ImageSlider(label="Before / After", show_label=False, interactive=False)
reuse_button = gr.Button("Reuse this image", visible=False)
gr.on(
triggers=[run_button.click, prompt.submit],
fn=infer,
inputs=[input_image, prompt, seed, randomize_seed, guidance_scale, steps],
outputs=[output_slider, seed, reuse_button]
)
reuse_button.click(
fn=lambda images: images[1] if isinstance(images, (list, tuple)) and len(images) > 1 else images,
inputs=[output_slider],
outputs=[input_image]
)
demo.launch(mcp_server=True, ssr_mode=False, show_error=True)
Parameter Settings
| Setting | Value |
|---|---|
| Module Type | Adapter |
| Base Model | FLUX.1 Kontext Dev - fp8 |
| Trigger Words | [photo content], remove any watermark text or logos from the image while preserving the background, texture, lighting, and overall realism. Ensure the edited areas blend seamlessly with surrounding details, leaving no visible traces of watermark removal. |
| Image Processing Repeats | 50 |
| Epochs | 25 |
| Save Every N Epochs | 1 |
Labeling: florence-community/Florence-2-large-ft (natural language & English)
Total Images Used for Training : 150 Image Pairs (75 Start, 75 End)
Training Parameters
| Setting | Value |
|---|---|
| Seed | - |
| Clip Skip | - |
| Text Encoder LR | 0.00001 |
| UNet LR | 0.00005 |
| LR Scheduler | constant |
| Optimizer | AdamW8bit |
| Network Dimension | 64 |
| Network Alpha | 32 |
| Gradient Accumulation Steps | - |
Label Parameters
| Setting | Value |
|---|---|
| Shuffle Caption | - |
| Keep N Tokens | - |
Advanced Parameters
| Setting | Value |
|---|---|
| Noise Offset | 0.03 |
| Multires Noise Discount | 0.1 |
| Multires Noise Iterations | 10 |
| Conv Dimension | - |
| Conv Alpha | - |
| Batch Size | - |
| Steps | 2900 & 400(warm up) |
| Sampler | euler |
Sample Inferences : Inference Providers
Trigger words
You should use [photo content] to trigger the image generation.
You should use remove any watermark text or logos from the image while preserving the background to trigger the image generation.
You should use texture to trigger the image generation.
You should use lighting to trigger the image generation.
You should use and overall realism. Ensure the edited areas blend seamlessly with surrounding details to trigger the image generation.
You should use leaving no visible traces of watermark removal. to trigger the image generation.
Download model
Download them in the Files & versions tab.
- Downloads last month
- -
Model tree for prithivMLmods/Kontext-Watermark-Remover
Base model
black-forest-labs/FLUX.1-Kontext-dev
