Hugging Face 用 Gradio 一条命令为 AI 生成内容添加可见水印
Visible Watermarking with Gradio
Hugging Face 在 Gradio 中内置可见水印功能,创建 Space 应用或 demo 时只需添加 watermark 参数即可为图像、视频和文本加水印。图像和视频通过 gr.Image、gr.Video 传入水印文件,支持图片或 numpy 数组,还可使用 QR 水印;文本则在 gr.Chatbot 中设置 watermark,用户复制 AI 回复时会自动附带水印署名。
Last year, we shared a blogpost on watermarking, explaining what it means to watermark generative AI content, and why it's important. The need for watermarking has become even more critical as people all over the world have begun to generate and share AI-generated images, video, audio, and text. Images and video have become so realistic that they’re nearly impossible to distinguish from what you’d see captured by a real camera. Addressing this issue is multi-faceted, but there is one, clear, low-hanging fruit 🍇:
In order for people to know what's real and what's synthetic, use visible watermarks.
To help out, we at Hugging Face have made visible watermarking trivially easy: Whenever you create a Space like an app or a demo, you can use our in-house app-building library Gradio to display watermarks with a single command.
For images and video, simply add the watermark parameter, like so:
gr.Image(my_generated_image, watermark=my_watermark_image)
gr.Video(my_generated_video, watermark=my_watermark_image)
See a demonstration of this in action: check out our example image and video watermarking Space.
Watermarks can be specified as filenames, and for images we additionally support open images or even numpy arrays, to work best with how you want to set up your interface. One option I particularly like is QR watermarks, which can be used to get much more information about the content, and can even be matched to the style of your image or video.
You can also add custom visible watermarks for AI-generated text, so that whenever it is copied, the watermark will appear. Like so:
gr.Chatbot(label=my_model_name, watermark=my_watermark_text, type="messages", show_copy_button=True, show_copy_all_button=True)
See a demonstration of this in action: check out our example chatbot watermarking Space.
This automatically adds attribution when users copy text from AI responses, further aiding in AI transparency and disclosure for text generation.
Try it all out today, build your own watermark, have fun!
Happy Coding!
Acknowledgements: Abubakar Abid and Yuvraj Sharma collaborated on this work and blog post.
来源:Hugging Face 社区博客 · huggingface.co
