Spaces:
Sleeping
Sleeping
Upload 6 files
Browse files- .gitignore +10 -0
- .python-version +1 -0
- README.md +0 -14
- app.py +102 -0
- pyproject.toml +11 -0
- uv.lock +0 -0
.gitignore
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Python-generated files
|
| 2 |
+
__pycache__/
|
| 3 |
+
*.py[oc]
|
| 4 |
+
build/
|
| 5 |
+
dist/
|
| 6 |
+
wheels/
|
| 7 |
+
*.egg-info
|
| 8 |
+
|
| 9 |
+
# Virtual environments
|
| 10 |
+
.venv
|
.python-version
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
3.13
|
README.md
CHANGED
|
@@ -1,14 +0,0 @@
|
|
| 1 |
-
---
|
| 2 |
-
title: Gemini Watermark
|
| 3 |
-
emoji: ⚡
|
| 4 |
-
colorFrom: gray
|
| 5 |
-
colorTo: green
|
| 6 |
-
sdk: gradio
|
| 7 |
-
sdk_version: 6.3.0
|
| 8 |
-
app_file: app.py
|
| 9 |
-
pinned: false
|
| 10 |
-
license: mit
|
| 11 |
-
short_description: Clean up gemini watermark
|
| 12 |
-
---
|
| 13 |
-
|
| 14 |
-
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
app.py
ADDED
|
@@ -0,0 +1,102 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import numpy as np
|
| 3 |
+
from PIL import Image
|
| 4 |
+
|
| 5 |
+
|
| 6 |
+
def get_map(p):
|
| 7 |
+
d = np.array(p.convert("RGB")).astype(float)
|
| 8 |
+
return np.max(d, axis=2) / 255.0
|
| 9 |
+
|
| 10 |
+
|
| 11 |
+
def rm_wm(img, m, x, y, strength):
|
| 12 |
+
h, w = m.shape
|
| 13 |
+
roi = img[y : y + h, x : x + w].astype(float)
|
| 14 |
+
m = np.clip(m * strength, 0, 0.99)
|
| 15 |
+
for i in range(3):
|
| 16 |
+
roi[:, :, i] = (roi[:, :, i] - m * 255) / (1 - m)
|
| 17 |
+
img[y : y + h, x : x + w] = np.clip(roi, 0, 255).astype(np.uint8)
|
| 18 |
+
return img
|
| 19 |
+
|
| 20 |
+
|
| 21 |
+
def clean(src, strength):
|
| 22 |
+
try:
|
| 23 |
+
if src is None:
|
| 24 |
+
return None, None
|
| 25 |
+
|
| 26 |
+
mask48 = Image.open("assets/bg_48.png")
|
| 27 |
+
mask96 = Image.open("assets/bg_96.png")
|
| 28 |
+
|
| 29 |
+
arr = np.array(src)
|
| 30 |
+
w, h = src.size
|
| 31 |
+
is_big = w > 1024 and h > 1024
|
| 32 |
+
sz, mg = (96, 64) if is_big else (48, 32)
|
| 33 |
+
mask = get_map(mask96 if is_big else mask48)
|
| 34 |
+
x, y = w - mg - sz, h - mg - sz
|
| 35 |
+
return src, Image.fromarray(rm_wm(arr, mask, x, y, strength))
|
| 36 |
+
except FileNotFoundError:
|
| 37 |
+
gr.Warning("Mask files not found in assets folder")
|
| 38 |
+
return src, src
|
| 39 |
+
except Exception as e:
|
| 40 |
+
gr.Warning(f"Error: {str(e)}")
|
| 41 |
+
return src, src
|
| 42 |
+
|
| 43 |
+
|
| 44 |
+
css = """
|
| 45 |
+
* {
|
| 46 |
+
font-family: 'Cascadia Code', 'Consolas', 'Monaco', monospace !important;
|
| 47 |
+
}
|
| 48 |
+
|
| 49 |
+
.gradio-container {
|
| 50 |
+
max-width: 1000px !important;
|
| 51 |
+
margin: auto !important;
|
| 52 |
+
}
|
| 53 |
+
|
| 54 |
+
#title {
|
| 55 |
+
font-size: 24px !important;
|
| 56 |
+
font-weight: 600 !important;
|
| 57 |
+
color: #1a1a1a !important;
|
| 58 |
+
margin-bottom: 8px !important;
|
| 59 |
+
}
|
| 60 |
+
|
| 61 |
+
#description {
|
| 62 |
+
color: #666 !important;
|
| 63 |
+
font-size: 14px !important;
|
| 64 |
+
margin-bottom: 24px !important;
|
| 65 |
+
}
|
| 66 |
+
|
| 67 |
+
.gr-button-primary {
|
| 68 |
+
background: #2563eb !important;
|
| 69 |
+
border: none !important;
|
| 70 |
+
color: white !important;
|
| 71 |
+
font-weight: 500 !important;
|
| 72 |
+
}
|
| 73 |
+
|
| 74 |
+
.gr-button-primary:hover {
|
| 75 |
+
background: #1d4ed8 !important;
|
| 76 |
+
}
|
| 77 |
+
|
| 78 |
+
input[type="range"] {
|
| 79 |
+
accent-color: #2563eb !important;
|
| 80 |
+
}
|
| 81 |
+
|
| 82 |
+
.image-container {
|
| 83 |
+
border: 1px solid #e5e7eb !important;
|
| 84 |
+
border-radius: 8px !important;
|
| 85 |
+
overflow: hidden !important;
|
| 86 |
+
}
|
| 87 |
+
"""
|
| 88 |
+
|
| 89 |
+
demo = gr.Interface(
|
| 90 |
+
fn=clean,
|
| 91 |
+
inputs=[
|
| 92 |
+
gr.Image(type="pil", label="Source Image"),
|
| 93 |
+
gr.Slider(minimum=0, maximum=2, value=1, step=0.1, label="Removal Strength"),
|
| 94 |
+
],
|
| 95 |
+
outputs=gr.ImageSlider(label="Original <-> Cleaned"),
|
| 96 |
+
title="Gemini Watermark Remover",
|
| 97 |
+
description="Credits: [Formula original](https://github.com/journey-ad/gemini-watermark-remover) // Source code: [Github](https://github.com/oopshnik/gemini)",
|
| 98 |
+
css=css,
|
| 99 |
+
)
|
| 100 |
+
|
| 101 |
+
if __name__ == "__main__":
|
| 102 |
+
demo.launch()
|
pyproject.toml
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
[project]
|
| 2 |
+
name = "se"
|
| 3 |
+
version = "0.1.0"
|
| 4 |
+
description = "Add your description here"
|
| 5 |
+
readme = "README.md"
|
| 6 |
+
requires-python = ">=3.13"
|
| 7 |
+
dependencies = [
|
| 8 |
+
"gradio>=6.3.0",
|
| 9 |
+
"numpy>=2.4.1",
|
| 10 |
+
"pillow>=12.1.0",
|
| 11 |
+
]
|
uv.lock
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|