Spaces:
Running
Running
File size: 4,216 Bytes
40e52db 88e4b1c a87a1d9 8e8b123 82e2c3a 88e4b1c 6d9b79c 88e4b1c 6d9b79c 82e2c3a 88e4b1c 6d9b79c 82e2c3a 6d9b79c 88e4b1c 82e2c3a 88e4b1c a87a1d9 a6626fd 88e4b1c ed66e9f a6626fd 6e83c08 88e4b1c 8b40206 ed66e9f 82e2c3a ed66e9f b024c7c 40e52db 82e2c3a 88e4b1c a87a1d9 0ce80a6 ed66e9f 0ce80a6 a87a1d9 0ce80a6 a87a1d9 82e2c3a ed66e9f a87a1d9 82e2c3a a87a1d9 82e2c3a 40e52db |
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 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 |
import gradio as gr
import os
css = """
p {
font-size: 120%;
}
li {
font-size: 110%;
}
html, body {
overflow: scroll;
}
video {
max-height: 400px;
}
.container {
height: initial;
}
.image-container {
width: 200px;
max-height: auto;
margin: auto;
}
img {
max-height: 400px;
}
"""
# Optional CSS stuff for the header example image:
#example {
# width: 80%;
# height: 60%
#}
#example img {
# width: 80%;
# height: 80%
#}
a = os.path.join(os.path.dirname(__file__), "files/barkley_balloon.mp4")
b = os.path.join(os.path.dirname(__file__), "files/eiffel_tower.mp4")
c = os.path.join(os.path.dirname(__file__), "files/bird.bmp")
d = os.path.join(os.path.dirname(__file__), "files/groot.jpeg")
w1 = os.path.join(os.path.dirname(__file__), "files/AI_generated.png")
w2 = os.path.join(os.path.dirname(__file__), "files/hf-logo.png")
w3 = os.path.join(os.path.dirname(__file__), "files/forest_qr_watermarking.png")
w4 = os.path.join(os.path.dirname(__file__), "files/cheetah1.jpg")
w5 = os.path.join(os.path.dirname(__file__), "files/frog.jpg")
w6 = os.path.join(os.path.dirname(__file__), "files/Human_generated.png")
w7 = os.path.join(os.path.dirname(__file__), "files/hf-logo_transpng.png")
def generate_image(original_image, watermark):
return gr.Image(original_image, watermark=watermark)
def generate_video(original_video, watermark):
return gr.Video(original_video, watermark=watermark)
with gr.Blocks(css=css) as demo:
with gr.Row():
with gr.Column():
gr.Markdown("# 🤗 Watermarking with Gradio: Example")
gr.Markdown("Watermarks can be **visible** or **invisible**.")
gr.Markdown("""They can provide information directly, or provide a link for more information.
- Visible watermarks are useful to disclose when content is AI-generated.
- Invisible watermarks can mark content as authentic.
- ...And vice versa! There are many possibilities for what watermarks can provide.
- Watermarks can also provide information about content created by people.""")
gr.Markdown("They are a useful tool for **AI provenance**.")
gr.Markdown()
gr.Markdown("""For more information on watermarking -- what watermarking is, why it's important, and the tools available on Hugging Face -- please check out [our blogpost on AI watermarking](https://huggingface.co/blog/watermarking).""")
gr.Markdown()
gr.Markdown("## Try it out below!")
with gr.Column():
with gr.Column():
gr.Image('files/watermark_example.png', visible=False)
with gr.Column():
gr.Image('files/watermark_example.png', show_label=False, show_download_button=False, elem_id='example', container=False, interactive=False)
gr.Markdown('**Image Watermark Code:**')
gr.Code('import gradio as gr\n\nwatermarked_image = gr.Image(original_image_file, watermark=watermark_file)', lines=3)
gr.Markdown('**Video Watermark Code:**')
gr.Code('import gradio as gr\n\nwatermarked_video = gr.Video(original_video_file, watermark=watermark_file)', lines=3)
with gr.Column():
gr.Image('files/watermark_example.png', visible=False)
with gr.Tab("Image Watermarking"):
with gr.Column():
gr.Markdown("**Inputs**: Image and watermark file")
with gr.Column():
gr.Markdown("**Output**: Watermarked image")
gr.Interface(generate_image, [gr.Image(), gr.Image(type='filepath', image_mode=None)], gr.Image(),
examples=[[d, w7], [w4, w5], [c, w6],])
with gr.Tab("Video Watermarking"):
with gr.Column():
gr.Markdown("**Inputs**: Video and watermark file")
with gr.Column():
gr.Markdown("**Output**: Watermarked video")
gr.Interface(generate_video, [gr.Video(), gr.Image(type='filepath', image_mode=None)], gr.Video(),
examples=[[a, w1], [b, w2], [a, w3], [b, w4]])
if __name__ == "__main__":
demo.launch() |