File size: 1,589 Bytes
8b37726
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
50bb5bf
8b37726
 
 
 
 
 
 
 
 
 
 
 
50bb5bf
8b37726
50bb5bf
8b37726
 
 
 
 
 
 
 
 
 
 
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
import gradio as gr
from PIL import Image
from PIL.PngImagePlugin import PngInfo
from io import BytesIO


def roundtrip(im, **options):
    out = BytesIO()
    im.save(out, "PNG", **options)
    out.seek(0)
    return Image.open(out)


def process_image(msg, img):
  targetImage = Image.open("1x1.png") if img is None else img
  metadata = PngInfo()
  metadata.add_text("parameters", msg+" Steps: 0, Hidden message added using: [promptinspector-abuser](https://huggingface.co/spaces/NoCrypt/promptinspector-abuser)")
  im = roundtrip(targetImage, pnginfo=metadata)
  status = "Hidden message added. Message: "+msg
  dl.interactive = True
  return im, status


with gr.Blocks() as demo:
    with gr.Row():
        with gr.Column():
            text = gr.Textbox(label="Hidden Message")
            input_img = gr.Image(elem_id="input", label="Input", interactive=True, type="pil", visible=False)
            btn = gr.Button(value="Submit", variant="primary")
        with gr.Column():
            status = gr.Textbox(label="Status", value="Ready", interactive=False)
            output = gr.Image(elem_id="output_image", label="Output", interactive=False, type="pil", visible=False)
            download = gr.Button(value="Download", interactive=True)

    btn.click(process_image, inputs=[text, input_img, download], outputs=[output, status, download])
    download.click(lambda x: x, inputs=[output], outputs=[output], _js="""
    (e)=>{
      var a = document.createElement("a");
      a.href = e;
      a.download = "output_hidden.png";
      a.click(); 
    }
    """)


demo.launch()