File size: 1,967 Bytes
44df56c |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
import gradio as gr
from image import add_and_detect_watermark_image
from video import add_and_detect_watermark_video
# Image Interface
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 Interface
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."
)
# Combine both interfaces in tabs
app = gr.TabbedInterface(
interface_list=[image_interface, video_interface],
tab_names=["Image", "Video"]
)
if __name__ == "__main__":
app.launch()
|