Spaces:
Running
Running
Upload 12 files
Browse files- .gitattributes +9 -0
- app.py +111 -0
- examples/1.jpg +3 -0
- examples/10.jpg +3 -0
- examples/2.jpg +3 -0
- examples/3.jpg +3 -0
- examples/4.jpg +3 -0
- examples/5.jpg +0 -0
- examples/6.jpg +3 -0
- examples/7.jpg +3 -0
- examples/8.jpg +3 -0
- examples/9.jpg +3 -0
- requirements.txt +5 -0
.gitattributes
CHANGED
|
@@ -33,3 +33,12 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
|
| 33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
| 34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
| 35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
| 34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
| 35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
| 36 |
+
examples/1.jpg filter=lfs diff=lfs merge=lfs -text
|
| 37 |
+
examples/10.jpg filter=lfs diff=lfs merge=lfs -text
|
| 38 |
+
examples/2.jpg filter=lfs diff=lfs merge=lfs -text
|
| 39 |
+
examples/3.jpg filter=lfs diff=lfs merge=lfs -text
|
| 40 |
+
examples/4.jpg filter=lfs diff=lfs merge=lfs -text
|
| 41 |
+
examples/6.jpg filter=lfs diff=lfs merge=lfs -text
|
| 42 |
+
examples/7.jpg filter=lfs diff=lfs merge=lfs -text
|
| 43 |
+
examples/8.jpg filter=lfs diff=lfs merge=lfs -text
|
| 44 |
+
examples/9.jpg filter=lfs diff=lfs merge=lfs -text
|
app.py
ADDED
|
@@ -0,0 +1,111 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from pathlib import Path
|
| 2 |
+
|
| 3 |
+
import gradio as gr
|
| 4 |
+
import pi_heif
|
| 5 |
+
import spaces
|
| 6 |
+
import requests
|
| 7 |
+
import base64
|
| 8 |
+
import io
|
| 9 |
+
import os
|
| 10 |
+
import json
|
| 11 |
+
from huggingface_hub import hf_hub_download
|
| 12 |
+
from PIL import Image
|
| 13 |
+
|
| 14 |
+
css = """
|
| 15 |
+
footer {display: none !important;}
|
| 16 |
+
"""
|
| 17 |
+
|
| 18 |
+
TITLE = """
|
| 19 |
+
<p>
|
| 20 |
+
Erase unwanted watermarks automatically with AI, no manual editing needed.
|
| 21 |
+
</p><p>
|
| 22 |
+
For premium-quality results,
|
| 23 |
+
<a href="https://nowatermark.cloud">try NoWatermark API</a>
|
| 24 |
+
— it's free to test!
|
| 25 |
+
</p>
|
| 26 |
+
"""
|
| 27 |
+
|
| 28 |
+
HEADERS = os.getenv("HEADERS")
|
| 29 |
+
API_HOST = os.getenv("API_HOST")
|
| 30 |
+
|
| 31 |
+
|
| 32 |
+
def remove_watermark(img_bytes):
|
| 33 |
+
headers = json.loads(HEADERS)
|
| 34 |
+
|
| 35 |
+
files = {
|
| 36 |
+
"original_preview_image": ("1.webp", img_bytes, "image/webp"),
|
| 37 |
+
}
|
| 38 |
+
|
| 39 |
+
data = {
|
| 40 |
+
"zoom_factor": 1,
|
| 41 |
+
"predict_mode": "old",
|
| 42 |
+
}
|
| 43 |
+
|
| 44 |
+
resp = requests.post(
|
| 45 |
+
API_HOST,
|
| 46 |
+
headers=headers,
|
| 47 |
+
files=files,
|
| 48 |
+
data=data,
|
| 49 |
+
)
|
| 50 |
+
if resp.status_code != 200:
|
| 51 |
+
print(f"Error: {resp.status_code} - {resp.text}")
|
| 52 |
+
return None
|
| 53 |
+
|
| 54 |
+
base64_image = resp.json().get("edited_image").get("image")
|
| 55 |
+
return base64.b64decode(base64_image)
|
| 56 |
+
|
| 57 |
+
def process(input_image):
|
| 58 |
+
"""
|
| 59 |
+
input_image: PIL.Image from Gradio
|
| 60 |
+
returns: PIL.Image (dewatermarked)
|
| 61 |
+
"""
|
| 62 |
+
# Convert PIL image to bytes (WebP, since your API expects webp)
|
| 63 |
+
img_bytes_io = io.BytesIO()
|
| 64 |
+
input_image.save(img_bytes_io, format="WEBP")
|
| 65 |
+
img_bytes = img_bytes_io.getvalue()
|
| 66 |
+
|
| 67 |
+
# Call your dewatermark function
|
| 68 |
+
result_bytes = remove_watermark(img_bytes)
|
| 69 |
+
if result_bytes is None:
|
| 70 |
+
return [input_image, input_image]
|
| 71 |
+
# return None # or return input_image as fallback
|
| 72 |
+
|
| 73 |
+
# Convert bytes back to PIL image
|
| 74 |
+
result_img = Image.open(io.BytesIO(result_bytes)).convert("RGB")
|
| 75 |
+
return [input_image, result_img]
|
| 76 |
+
|
| 77 |
+
with gr.Blocks(css=css) as demo:
|
| 78 |
+
gr.HTML(TITLE)
|
| 79 |
+
|
| 80 |
+
with gr.Row():
|
| 81 |
+
with gr.Column():
|
| 82 |
+
input_image = gr.Image(type="pil", label="Input Image")
|
| 83 |
+
run_button = gr.ClearButton(components=None, value="Remove Watermark")
|
| 84 |
+
with gr.Column():
|
| 85 |
+
output_slider = gr.ImageSlider(label="Before / After", max_height=1200, show_fullscreen_button=False)
|
| 86 |
+
run_button.add(output_slider)
|
| 87 |
+
|
| 88 |
+
run_button.click(fn=process, inputs=input_image, outputs=output_slider, api_name=False)
|
| 89 |
+
|
| 90 |
+
gr.Examples(
|
| 91 |
+
examples=[
|
| 92 |
+
"examples/1.jpg",
|
| 93 |
+
"examples/2.jpg",
|
| 94 |
+
"examples/3.jpg",
|
| 95 |
+
"examples/4.jpg",
|
| 96 |
+
"examples/5.jpg",
|
| 97 |
+
"examples/6.jpg",
|
| 98 |
+
"examples/7.jpg",
|
| 99 |
+
"examples/8.jpg",
|
| 100 |
+
"examples/9.jpg",
|
| 101 |
+
"examples/10.jpg",
|
| 102 |
+
],
|
| 103 |
+
inputs=[input_image],
|
| 104 |
+
outputs=output_slider,
|
| 105 |
+
fn=process,
|
| 106 |
+
cache_examples=True,
|
| 107 |
+
cache_mode="lazy",
|
| 108 |
+
run_on_click=False,
|
| 109 |
+
)
|
| 110 |
+
|
| 111 |
+
demo.launch(share=False, ssr_mode=False, show_api=False)
|
examples/1.jpg
ADDED
|
Git LFS Details
|
examples/10.jpg
ADDED
|
Git LFS Details
|
examples/2.jpg
ADDED
|
Git LFS Details
|
examples/3.jpg
ADDED
|
Git LFS Details
|
examples/4.jpg
ADDED
|
Git LFS Details
|
examples/5.jpg
ADDED
|
examples/6.jpg
ADDED
|
Git LFS Details
|
examples/7.jpg
ADDED
|
Git LFS Details
|
examples/8.jpg
ADDED
|
Git LFS Details
|
examples/9.jpg
ADDED
|
Git LFS Details
|
requirements.txt
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
spaces>=0.35.0
|
| 2 |
+
gradio_imageslider==0.0.20
|
| 3 |
+
numpy<2.0.0
|
| 4 |
+
pillow>=11.3.0
|
| 5 |
+
pi_heif>=1.1.0
|