|
import gradio as gr |
|
from image import add_and_detect_watermark_image |
|
from video import add_and_detect_watermark_video |
|
|
|
|
|
image_inputs = [ |
|
gr.Image(type="numpy", label="Upload Image"), |
|
gr.Textbox(label="Watermark Text") |
|
] |
|
|
|
image_outputs = [ |
|
gr.Image(type="numpy", label="Watermarked Image"), |
|
gr.Image(type="numpy", label="Watermark Highlight"), |
|
gr.File(label="Download Watermarked Image"), |
|
gr.File(label="Download Watermark Highlight") |
|
] |
|
|
|
def process_image(image, text): |
|
watermarked_image, highlight, watermarked_image_path, highlight_path = add_and_detect_watermark_image(image, text) |
|
return watermarked_image, highlight, watermarked_image_path, highlight_path |
|
|
|
image_interface = gr.Interface( |
|
fn=process_image, |
|
inputs=image_inputs, |
|
outputs=image_outputs, |
|
title="Image Watermark Application", |
|
description="Upload an image and add a watermark text. Detect watermark and highlight its position." |
|
) |
|
|
|
|
|
video_inputs = [ |
|
gr.Video(label="Upload Video"), |
|
gr.Textbox(label="Watermark Text") |
|
] |
|
|
|
video_outputs = [ |
|
gr.Video(label="Watermarked Video"), |
|
gr.Video(label="Watermark Highlight"), |
|
gr.File(label="Download Watermarked Video"), |
|
gr.File(label="Download Watermark Highlight") |
|
] |
|
|
|
def process_video(video, text): |
|
watermarked_video_path, highlight_video_path, _, _ = add_and_detect_watermark_video(video, text) |
|
return watermarked_video_path, highlight_video_path, watermarked_video_path, highlight_video_path |
|
|
|
video_interface = gr.Interface( |
|
fn=process_video, |
|
inputs=video_inputs, |
|
outputs=video_outputs, |
|
title="Video Watermark Application", |
|
description="Upload a video and add a watermark text. Detect watermark and highlight its position." |
|
) |
|
|
|
|
|
app = gr.TabbedInterface( |
|
interface_list=[image_interface, video_interface], |
|
tab_names=["Image", "Video"] |
|
) |
|
|
|
if __name__ == "__main__": |
|
app.launch() |
|
|