luzasd commited on
Commit
44df56c
·
verified ·
1 Parent(s): 283b04d

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +62 -0
app.py ADDED
@@ -0,0 +1,62 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from image import add_and_detect_watermark_image
3
+ from video import add_and_detect_watermark_video
4
+
5
+ # Image Interface
6
+ image_inputs = [
7
+ gr.Image(type="numpy", label="Upload Image"),
8
+ gr.Textbox(label="Watermark Text")
9
+ ]
10
+
11
+ image_outputs = [
12
+ gr.Image(type="numpy", label="Watermarked Image"),
13
+ gr.Image(type="numpy", label="Watermark Highlight"),
14
+ gr.File(label="Download Watermarked Image"),
15
+ gr.File(label="Download Watermark Highlight")
16
+ ]
17
+
18
+ def process_image(image, text):
19
+ watermarked_image, highlight, watermarked_image_path, highlight_path = add_and_detect_watermark_image(image, text)
20
+ return watermarked_image, highlight, watermarked_image_path, highlight_path
21
+
22
+ image_interface = gr.Interface(
23
+ fn=process_image,
24
+ inputs=image_inputs,
25
+ outputs=image_outputs,
26
+ title="Image Watermark Application",
27
+ description="Upload an image and add a watermark text. Detect watermark and highlight its position."
28
+ )
29
+
30
+ # Video Interface
31
+ video_inputs = [
32
+ gr.Video(label="Upload Video"),
33
+ gr.Textbox(label="Watermark Text")
34
+ ]
35
+
36
+ video_outputs = [
37
+ gr.Video(label="Watermarked Video"),
38
+ gr.Video(label="Watermark Highlight"),
39
+ gr.File(label="Download Watermarked Video"),
40
+ gr.File(label="Download Watermark Highlight")
41
+ ]
42
+
43
+ def process_video(video, text):
44
+ watermarked_video_path, highlight_video_path, _, _ = add_and_detect_watermark_video(video, text)
45
+ return watermarked_video_path, highlight_video_path, watermarked_video_path, highlight_video_path
46
+
47
+ video_interface = gr.Interface(
48
+ fn=process_video,
49
+ inputs=video_inputs,
50
+ outputs=video_outputs,
51
+ title="Video Watermark Application",
52
+ description="Upload a video and add a watermark text. Detect watermark and highlight its position."
53
+ )
54
+
55
+ # Combine both interfaces in tabs
56
+ app = gr.TabbedInterface(
57
+ interface_list=[image_interface, video_interface],
58
+ tab_names=["Image", "Video"]
59
+ )
60
+
61
+ if __name__ == "__main__":
62
+ app.launch()