File size: 1,243 Bytes
3382d24
 
 
 
 
 
 
 
 
 
 
 
c39105a
3382d24
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
48
49
50
51
52
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()