picinfo / app.py
chewing's picture
Update app.py
c39105a verified
import gradio as gr
import html
def greet(name):
return "Hello " + name + "!!"
css = """
#generate {
height: 100%;
}
"""
with gr.Blocks(css=css) as demo:
with gr.Tab("PNG Info"):
def plaintext_to_html(text, classname=None):
content = "<br>\n".join(html.escape(x) for x in text.split('\n'))
return f"<p class='{classname}'>{content}</p>" if classname else f"<p>{content}</p>"
def get_exif_data(image):
items = image.info
info = ''
for key, text in items.items():
info += f"""
<div>
<p><b>{plaintext_to_html(str(key))}</b></p>
<p>{plaintext_to_html(str(text))}</p>
</div>
""".strip() + "\n"
if len(info) == 0:
message = "Nothing found in the image."
info = f"<div><p>{message}<p></div>"
return info
with gr.Row():
with gr.Column():
image_input = gr.Image(type="pil")
with gr.Column():
exif_output = gr.HTML(label="EXIF Data")
image_input.upload(get_exif_data, inputs=[image_input], outputs=exif_output)
demo.launch()