ahmedghani commited on
Commit
732b864
β€’
1 Parent(s): c6e19d0

added image watermark remover

Browse files
Files changed (2) hide show
  1. app.py +40 -20
  2. image_watermark_remover.py +61 -0
app.py CHANGED
@@ -2,6 +2,7 @@ import gradio as gr
2
  from video_watermark_remover import *
3
  from video_convertor import *
4
  from image_convertor import *
 
5
 
6
  css = """
7
  #remove_btn {
@@ -29,6 +30,44 @@ css = """
29
 
30
  demo = gr.Blocks(css=css, title="Video Watermark Remover")
31
  with demo:
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
32
  with gr.Tab("Video Watermark Remover"):
33
  gr.Markdown("""
34
  # <center>πŸŽ₯ Video Watermark Remover (Slow)</center>
@@ -78,26 +117,7 @@ with demo:
78
  format.change(lambda x: gr.Button.update(interactive=True), None, outputs=[convert_btn])
79
  convert_btn.click(convert_video, inputs=[input_video, format], outputs=[output, status])
80
 
81
- with gr.Tab("Image Convertor"):
82
- gr.Markdown("""
83
- # <center>πŸ–ΌοΈ Image Convertor</center>
84
- """)
85
- image_format = ['jpg', 'jpeg', 'png', 'bmp', 'tiff', 'gif', 'webp', 'ico', 'heic', 'heiv', 'heif']
86
- with gr.Row():
87
- with gr.Column():
88
- input_image = gr.File(label="Upload an Image")
89
- with gr.Column():
90
- with gr.Row():
91
- with gr.Row():
92
- image_format = gr.Radio(image_format, label="Select Format", interactive=False)
93
- with gr.Row():
94
- image_convert_btn = gr.Button("Convert Image", interactive=False, elem_id="convert_btn")
95
- with gr.Row():
96
- output_image = gr.File(label="Output File", interactive=False)
97
- image_status = gr.Textbox(label="Status", interactive=False)
98
- input_image.change(lambda x: gr.Radio.update(interactive=True), inputs=[input_image], outputs=[image_format])
99
- image_format.change(lambda x: gr.Button.update(interactive=True), None, outputs=[image_convert_btn])
100
- image_convert_btn.click(convert_image, inputs=[input_image, image_format], outputs=[output_image, image_status])
101
  gr.Markdown("""## <center style="margin:20px;">Developed by Muhammad Ahmed<img src="https://avatars.githubusercontent.com/u/63394104?v=4" style="height:50px;width:50px;border-radius:50%;margin:5px;"></img></center>
102
  """)
103
  demo.launch(show_api=False)
 
2
  from video_watermark_remover import *
3
  from video_convertor import *
4
  from image_convertor import *
5
+ from image_watermark_remover import *
6
 
7
  css = """
8
  #remove_btn {
 
30
 
31
  demo = gr.Blocks(css=css, title="Video Watermark Remover")
32
  with demo:
33
+ with gr.Tab("Image Convertor"):
34
+ gr.Markdown("""
35
+ # <center>πŸ–ΌοΈ Image Convertor</center>
36
+ """)
37
+ image_format = ['jpg', 'jpeg', 'png', 'bmp', 'tiff', 'gif', 'webp', 'ico', 'heic', 'heiv', 'heif']
38
+ with gr.Row():
39
+ with gr.Column():
40
+ input_image = gr.File(label="Upload an Image")
41
+ with gr.Column():
42
+ with gr.Row():
43
+ with gr.Row():
44
+ image_format = gr.Radio(image_format, label="Select Format", interactive=False)
45
+ with gr.Row():
46
+ image_convert_btn = gr.Button("Convert Image", interactive=False, elem_id="convert_btn")
47
+ with gr.Row():
48
+ output_image = gr.File(label="Output File", interactive=False)
49
+ image_status = gr.Textbox(label="Status", interactive=False)
50
+ input_image.change(lambda x: gr.Radio.update(interactive=True), inputs=[input_image], outputs=[image_format])
51
+ image_format.change(lambda x: gr.Button.update(interactive=True), None, outputs=[image_convert_btn])
52
+ image_convert_btn.click(convert_image, inputs=[input_image, image_format], outputs=[output_image, image_status])
53
+
54
+ with gr.Tab("Image Watermark Remover"):
55
+ gr.Markdown("""
56
+ # <center>πŸ–ΌοΈ Image Watermark Remover</center>
57
+ """)
58
+ with gr.Row():
59
+ with gr.Column():
60
+ input_image_watermark = gr.Image(label="Upload an Image", tool="sketch", type="pil", interactive=True)
61
+ with gr.Row():
62
+ with gr.Column():
63
+ pass
64
+ with gr.Column():
65
+ image_remove_btn = gr.Button("Remove Watermark", interactive=False, elem_id="remove_btn")
66
+ with gr.Column():
67
+ pass
68
+ output_image_clean = gr.Image(label="Output Image", interactive=True)
69
+ image_remove_btn.click(remove_image_watermark, inputs=[input_image_watermark], outputs=[output_image_clean])
70
+
71
  with gr.Tab("Video Watermark Remover"):
72
  gr.Markdown("""
73
  # <center>πŸŽ₯ Video Watermark Remover (Slow)</center>
 
117
  format.change(lambda x: gr.Button.update(interactive=True), None, outputs=[convert_btn])
118
  convert_btn.click(convert_video, inputs=[input_video, format], outputs=[output, status])
119
 
120
+
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
121
  gr.Markdown("""## <center style="margin:20px;">Developed by Muhammad Ahmed<img src="https://avatars.githubusercontent.com/u/63394104?v=4" style="height:50px;width:50px;border-radius:50%;margin:5px;"></img></center>
122
  """)
123
  demo.launch(show_api=False)
image_watermark_remover.py ADDED
@@ -0,0 +1,61 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import io
2
+ import requests
3
+ from PIL import Image
4
+
5
+ def remove_image_watermark(input):
6
+ image = input["image"]
7
+ mask = input["mask"]
8
+ image_data = io.BytesIO()
9
+ image.save(image_data, format=image.format)
10
+ image_data = image_data.getvalue()
11
+
12
+ mask_data = io.BytesIO()
13
+ mask.save(mask_data, format=mask.format)
14
+ mask_data = mask_data.getvalue()
15
+
16
+ # Prepare form data
17
+ form_data = {
18
+ 'ldmSteps': 25,
19
+ 'ldmSampler': 'plms',
20
+ 'zitsWireframe': True,
21
+ 'hdStrategy': 'Original',
22
+ 'hdStrategyCropMargin': 196,
23
+ 'hdStrategyCropTrigerSize': 1280,
24
+ 'hdStrategyResizeLimit': 2048,
25
+ 'prompt': '',
26
+ 'negativePrompt': '',
27
+ 'croperX': -24,
28
+ 'croperY': -23,
29
+ 'croperHeight': 512,
30
+ 'croperWidth': 512,
31
+ 'useCroper': False,
32
+ 'sdMaskBlur': 5,
33
+ 'sdStrength': 0.75,
34
+ 'sdSteps': 50,
35
+ 'sdGuidanceScale': 7.5,
36
+ 'sdSampler': 'pndm',
37
+ 'sdSeed': 42,
38
+ 'sdMatchHistograms': False,
39
+ 'sdScale': 1,
40
+ 'cv2Radius': 5,
41
+ 'cv2Flag': 'INPAINT_NS',
42
+ 'paintByExampleSteps': 50,
43
+ 'paintByExampleGuidanceScale': 7.5,
44
+ 'paintByExampleSeed': 42,
45
+ 'paintByExampleMaskBlur': 5,
46
+ 'paintByExampleMatchHistograms': False,
47
+ 'sizeLimit': 1024,
48
+ }
49
+
50
+ files_data = {
51
+ 'image': ('image.png', image_data),
52
+ 'mask': ('mask.png', mask_data)
53
+ }
54
+
55
+ response = requests.post('https://ahmedghani-lama-cleaner-lama.hf.space/inpaint', data=form_data, files=files_data)
56
+
57
+ if response.headers['Content-Type'] == 'image/jpeg' or response.headers['Content-Type'] == 'image/png':
58
+ image = Image.open(io.BytesIO(response.content))
59
+ return image
60
+ else:
61
+ print(f"Error processing Image: {response.text}")