NoCrypt commited on
Commit
8b37726
1 Parent(s): 8c27882

initial commit

Browse files
Files changed (2) hide show
  1. 1x1.png +0 -0
  2. app.py +45 -0
1x1.png ADDED
app.py ADDED
@@ -0,0 +1,45 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from PIL import Image
3
+ from PIL.PngImagePlugin import PngInfo
4
+ from io import BytesIO
5
+
6
+
7
+ def roundtrip(im, **options):
8
+ out = BytesIO()
9
+ im.save(out, "PNG", **options)
10
+ out.seek(0)
11
+ return Image.open(out)
12
+
13
+
14
+ def process_image(msg, img):
15
+ targetImage = Image.open("1x1.png") if img is None else img
16
+ metadata = PngInfo()
17
+ metadata.add_text("parameters", msg+" Steps: 0, Hidden message added using: [promptinspector-abuser](https://huggingface.co/spaces/NoCrypt/promptinspector-abuser)")
18
+ im = roundtrip(targetImage, pnginfo=metadata)
19
+ status = "Hidden message added. Message: "+msg
20
+ return im, status
21
+
22
+
23
+ with gr.Blocks() as demo:
24
+ with gr.Row():
25
+ with gr.Column():
26
+ text = gr.Textbox(label="Hidden Message")
27
+ input_img = gr.Image(elem_id="input", label="Input", interactive=True, type="pil", visible=False)
28
+ btn = gr.Button(value="Submit", variant="primary")
29
+ with gr.Column():
30
+ status = gr.Textbox(label="Status", value="Ready", interactive=False)
31
+ output = gr.Image(elem_id="output_image", label="Output", interactive=False, type="pil", visible=False)
32
+ download = gr.Button(value="Download", interactive=False)
33
+
34
+ btn.click(process_image, inputs=[text, input_img], outputs=[output, status])
35
+ download.click(lambda x: x, inputs=[output], outputs=[output], _js="""
36
+ (e)=>{
37
+ var a = document.createElement("a");
38
+ a.href = e;
39
+ a.download = "output_hidden.png";
40
+ a.click();
41
+ }
42
+ """)
43
+
44
+
45
+ demo.launch()