Update app.py
Browse files
app.py
CHANGED
|
@@ -26,11 +26,26 @@ def remove_watermark_area(original_image, text_mask_path):
|
|
| 26 |
cleaned_image = cv2.GaussianBlur(inpainted_image, (3, 3), 0)
|
| 27 |
|
| 28 |
return cleaned_image
|
|
|
|
| 29 |
|
| 30 |
def remove_watermark(image_path,saved_path):
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 34 |
# Define the area of the watermark (adjust this based on the watermark size)
|
| 35 |
height, width, _ = image.shape
|
| 36 |
watermark_width = 185 # Adjust based on your watermark size
|
|
@@ -65,6 +80,12 @@ def random_image_name():
|
|
| 65 |
return str(uuid.uuid4())[:8]
|
| 66 |
|
| 67 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 68 |
def process_files(image_files):
|
| 69 |
image_list = []
|
| 70 |
if len(image_files) == 1:
|
|
@@ -83,14 +104,29 @@ def process_files(image_files):
|
|
| 83 |
zip_path = make_zip(image_list)
|
| 84 |
return zip_path,None
|
| 85 |
|
|
|
|
| 86 |
if not os.path.exists("./temp"):
|
| 87 |
os.mkdir("./temp")
|
| 88 |
|
| 89 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 90 |
process_files,
|
| 91 |
[gr.File(type='filepath', file_count='multiple')],
|
| 92 |
[gr.File(),gr.Image()],
|
| 93 |
cache_examples=True
|
| 94 |
)
|
| 95 |
|
|
|
|
| 96 |
demo.launch(debug=True)
|
|
|
|
|
|
| 26 |
cleaned_image = cv2.GaussianBlur(inpainted_image, (3, 3), 0)
|
| 27 |
|
| 28 |
return cleaned_image
|
| 29 |
+
from PIL import Image
|
| 30 |
|
| 31 |
def remove_watermark(image_path,saved_path):
|
| 32 |
+
if isinstance(image_path, str) and os.path.isfile(image_path):
|
| 33 |
+
# Load the image using OpenCV
|
| 34 |
+
image = cv2.imread(image_path)
|
| 35 |
+
elif isinstance(image_path, np.ndarray):
|
| 36 |
+
# Directly use OpenCV image (NumPy array)
|
| 37 |
+
image = image_path
|
| 38 |
+
if len(image_path.shape) == 3 and image_path.shape[2] == 3:
|
| 39 |
+
# Assuming it's in RGB format; convert to BGR
|
| 40 |
+
image = cv2.cvtColor(image_path, cv2.COLOR_RGB2BGR)
|
| 41 |
+
else:
|
| 42 |
+
# Otherwise, assume it's already in BGR format
|
| 43 |
+
image = image_path
|
| 44 |
+
else:
|
| 45 |
+
raise TypeError("Invalid image_path format")
|
| 46 |
+
print(type(image))
|
| 47 |
+
cv2.imwrite("test.jpg",image)
|
| 48 |
+
image=cv2.resize(image,(1280,1280))
|
| 49 |
# Define the area of the watermark (adjust this based on the watermark size)
|
| 50 |
height, width, _ = image.shape
|
| 51 |
watermark_width = 185 # Adjust based on your watermark size
|
|
|
|
| 80 |
return str(uuid.uuid4())[:8]
|
| 81 |
|
| 82 |
|
| 83 |
+
def process_file(pil_image):
|
| 84 |
+
saved_path = f"./temp/{random_image_name()}.jpg"
|
| 85 |
+
remove_watermark(pil_image, saved_path)
|
| 86 |
+
return saved_path, saved_path
|
| 87 |
+
|
| 88 |
+
|
| 89 |
def process_files(image_files):
|
| 90 |
image_list = []
|
| 91 |
if len(image_files) == 1:
|
|
|
|
| 104 |
zip_path = make_zip(image_list)
|
| 105 |
return zip_path,None
|
| 106 |
|
| 107 |
+
|
| 108 |
if not os.path.exists("./temp"):
|
| 109 |
os.mkdir("./temp")
|
| 110 |
|
| 111 |
+
|
| 112 |
+
meta_examples = ["./images/1.jpg", "./images/2.jpg", "./images/3.jpg", "./images/4.jpg", "./images/5.jpg", "./images/6.jpg"]
|
| 113 |
+
|
| 114 |
+
gradio_input=[gr.Image()]
|
| 115 |
+
gradio_Output=[gr.File(),gr.Image()]
|
| 116 |
+
gradio_interface = gr.Interface(fn=process_file, inputs=gradio_input,outputs=gradio_Output ,
|
| 117 |
+
title="Meta Watermark Remover",
|
| 118 |
+
examples=meta_examples)
|
| 119 |
+
# gradio_interface.launch(debug=True)
|
| 120 |
+
|
| 121 |
+
|
| 122 |
+
|
| 123 |
+
gradio_multiple_images = gr.Interface(
|
| 124 |
process_files,
|
| 125 |
[gr.File(type='filepath', file_count='multiple')],
|
| 126 |
[gr.File(),gr.Image()],
|
| 127 |
cache_examples=True
|
| 128 |
)
|
| 129 |
|
| 130 |
+
demo = gr.TabbedInterface([gradio_interface, gradio_multiple_images], ["Meta Watermark Remover","Bluk Meta Watermark Remover"],title="Meta Watermark Remover")
|
| 131 |
demo.launch(debug=True)
|
| 132 |
+
|