Spaces:
Runtime error
Runtime error
montyanderson
commited on
Commit
•
bab1e75
1
Parent(s):
d245bfd
`app.py`: show exif data in html
Browse files
app.py
CHANGED
@@ -8,6 +8,7 @@ import os
|
|
8 |
from io import BytesIO
|
9 |
import PIL
|
10 |
from PIL.ExifTags import TAGS
|
|
|
11 |
|
12 |
|
13 |
class Prodia:
|
@@ -174,15 +175,36 @@ with gr.Blocks(css=css) as demo:
|
|
174 |
text_button.click(flip_text, inputs=[prompt, negative_prompt, model, steps, sampler, cfg_scale, width, height, seed], outputs=image_output)
|
175 |
|
176 |
with gr.Tab("PNG Info"):
|
|
|
|
|
|
|
|
|
|
|
|
|
177 |
def get_exif_data(image):
|
178 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
179 |
|
180 |
with gr.Row():
|
181 |
with gr.Column():
|
182 |
image_input = gr.Image(type="pil")
|
183 |
|
184 |
with gr.Column():
|
185 |
-
exif_output = gr.
|
186 |
|
187 |
image_input.upload(get_exif_data, inputs=[image_input], outputs=exif_output)
|
188 |
|
|
|
8 |
from io import BytesIO
|
9 |
import PIL
|
10 |
from PIL.ExifTags import TAGS
|
11 |
+
import html
|
12 |
|
13 |
|
14 |
class Prodia:
|
|
|
175 |
text_button.click(flip_text, inputs=[prompt, negative_prompt, model, steps, sampler, cfg_scale, width, height, seed], outputs=image_output)
|
176 |
|
177 |
with gr.Tab("PNG Info"):
|
178 |
+
def plaintext_to_html(text, classname=None):
|
179 |
+
content = "<br>\n".join(html.escape(x) for x in text.split('\n'))
|
180 |
+
|
181 |
+
return f"<p class='{classname}'>{content}</p>" if classname else f"<p>{content}</p>"
|
182 |
+
|
183 |
+
|
184 |
def get_exif_data(image):
|
185 |
+
items = image.info
|
186 |
+
|
187 |
+
info = ''
|
188 |
+
for key, text in items.items():
|
189 |
+
info += f"""
|
190 |
+
<div>
|
191 |
+
<p><b>{plaintext_to_html(str(key))}</b></p>
|
192 |
+
<p>{plaintext_to_html(str(text))}</p>
|
193 |
+
</div>
|
194 |
+
""".strip()+"\n"
|
195 |
+
|
196 |
+
if len(info) == 0:
|
197 |
+
message = "Nothing found in the image."
|
198 |
+
info = f"<div><p>{message}<p></div>"
|
199 |
+
|
200 |
+
return info
|
201 |
|
202 |
with gr.Row():
|
203 |
with gr.Column():
|
204 |
image_input = gr.Image(type="pil")
|
205 |
|
206 |
with gr.Column():
|
207 |
+
exif_output = gr.HTML(label="EXIF Data")
|
208 |
|
209 |
image_input.upload(get_exif_data, inputs=[image_input], outputs=exif_output)
|
210 |
|