ankanpy commited on
Commit
a6f3342
·
1 Parent(s): f9936e7

updated code for gradio 5

Browse files
Files changed (2) hide show
  1. README.md +1 -1
  2. app.py +8 -7
README.md CHANGED
@@ -4,7 +4,7 @@ emoji: 👀
4
  colorFrom: green
5
  colorTo: gray
6
  sdk: gradio
7
- sdk_version: 4.42.0
8
  app_file: app.py
9
  pinned: false
10
  license: mit
 
4
  colorFrom: green
5
  colorTo: gray
6
  sdk: gradio
7
+ sdk_version: 5.23.3
8
  app_file: app.py
9
  pinned: false
10
  license: mit
app.py CHANGED
@@ -3,13 +3,12 @@ import numpy as np
3
  import gradio as gr
4
 
5
 
6
-
7
  def apply_watermark(img, logo, mode):
8
-
9
  # change the mode to BGR for processing
10
  img = cv2.cvtColor(img, cv2.COLOR_RGB2BGR)
11
  logo = cv2.cvtColor(logo, cv2.COLOR_RGBA2BGRA)
12
-
13
  # Get dimensions of the main image and watermark
14
  main_height, main_width = img.shape[:2]
15
  watermark_height, watermark_width = logo.shape[:2]
@@ -25,7 +24,7 @@ def apply_watermark(img, logo, mode):
25
 
26
  # Place the watermark
27
  roi = img[y : y + watermark_height, x : x + watermark_width]
28
-
29
  # Separate the color and alpha channels.
30
  # print(logo.shape)
31
  logo_bgr = logo[:, :, 0:3]
@@ -44,7 +43,6 @@ def apply_watermark(img, logo, mode):
44
 
45
  if mode == "Opaque":
46
 
47
-
48
  # Combine the masked ROI with the masked logo to get the combined ROI image.
49
  roi_final = cv2.bitwise_or(masked_roi, masked_logo)
50
 
@@ -89,8 +87,11 @@ interface = gr.Interface(
89
  outputs=[final_output],
90
  title="OpenCV Watermark",
91
  description="Upload your Input Image and choose a logo to create your watermark image!",
92
- examples=[["./images/hp-2.jpg", "./images/opencv-logo-rz.png"], ["./images/hp.jpg", "./images/opencv-university-rz.png"]],
 
 
 
93
  cache_examples=False,
94
  )
95
 
96
- interface.launch()
 
3
  import gradio as gr
4
 
5
 
 
6
  def apply_watermark(img, logo, mode):
7
+
8
  # change the mode to BGR for processing
9
  img = cv2.cvtColor(img, cv2.COLOR_RGB2BGR)
10
  logo = cv2.cvtColor(logo, cv2.COLOR_RGBA2BGRA)
11
+
12
  # Get dimensions of the main image and watermark
13
  main_height, main_width = img.shape[:2]
14
  watermark_height, watermark_width = logo.shape[:2]
 
24
 
25
  # Place the watermark
26
  roi = img[y : y + watermark_height, x : x + watermark_width]
27
+
28
  # Separate the color and alpha channels.
29
  # print(logo.shape)
30
  logo_bgr = logo[:, :, 0:3]
 
43
 
44
  if mode == "Opaque":
45
 
 
46
  # Combine the masked ROI with the masked logo to get the combined ROI image.
47
  roi_final = cv2.bitwise_or(masked_roi, masked_logo)
48
 
 
87
  outputs=[final_output],
88
  title="OpenCV Watermark",
89
  description="Upload your Input Image and choose a logo to create your watermark image!",
90
+ examples=[
91
+ ["./images/hp-2.jpg", "./images/opencv-logo-rz.png"],
92
+ ["./images/hp.jpg", "./images/opencv-university-rz.png"],
93
+ ],
94
  cache_examples=False,
95
  )
96
 
97
+ interface.launch()