alfredplpl's picture
Update app.py
4bbad46 verified
raw
history blame
1.2 kB
from imwatermark import WatermarkDecoder
import gradio as gr
# https://github.com/huggingface/diffusers/blob/main/src/diffusers/pipelines/stable_diffusion_xl/watermark.py
# Copied from https://github.com/Stability-AI/generative-models/blob/613af104c6b85184091d42d374fef420eddb356d/scripts/demo/streamlit_helpers.py#L66
WATERMARK_MESSAGE = 0b101100111110110010010000011110111011000110011110
# bin(x)[2:] gives bits of x as str, use int to convert them to 0/1
WATERMARK_BITS = [int(bit) for bit in bin(WATERMARK_MESSAGE)[2:]]
def detect_watermark(image):
decoder = WatermarkDecoder('bytes', 32)
watermark = decoder.decode(image, 'dwtDct')
print(watermark.decode())
return "ไฝ•ใ‚‚ใ‚ใ‹ใ‚Šใพใ›ใ‚“ใงใ—ใŸใ€‚"
#return "ใ“ใฎ็”ปๅƒใฏdiffusersใงไฝœใ‚‰ใ‚ŒใŸๅฏ่ƒฝๆ€งใŒใ‚ใ‚Šใพใ™ใ€‚"
gr.Interface(fn=detect_watermark,
title="AI็”ปๅƒ็ฐกๆ˜“ใƒใ‚งใƒƒใ‚ฏใƒ„ใƒผใƒซ",
description="ๆŒ‡ๅฎšใฎ็”ปๅƒใŒ็”ปๅƒ็”ŸๆˆAIใซใ‚ˆใฃใฆไฝœใ‚‰ใ‚ŒใŸใ‚‚ใฎใ‹ใ‚’็ฐกๆ˜“็š„ใซๅˆคๅฎšใ—ใพใ™ใ€‚ใ“ใฎใƒ„ใƒผใƒซใงๅˆคๅฎšใ—ใŸใ“ใจใ‚’ๆฑบใ—ใฆๆ–ญๅฎš็š„ใซ็”จใ„ใชใ„ใงใใ ใ•ใ„ใ€‚",
inputs=gr.Image(type="numpy"),
outputs=gr.Textbox()).launch()