chewing commited on
Commit
3382d24
·
verified ·
1 Parent(s): 7eba821

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +50 -0
app.py ADDED
@@ -0,0 +1,50 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import html
3
+
4
+ def greet(name):
5
+ return "Hello " + name + "!!"
6
+
7
+ css = """
8
+ #generate {
9
+ height: 100%;
10
+ }
11
+ """
12
+
13
+ with gr.Blocks(css=css) as demo:
14
+ with gr.Tab("PNG Info"):
15
+ def plaintext_to_html(text, classname=None):
16
+ content = "<br>\n".join(html.escape(x) for x in text.split('\n'))
17
+
18
+ return f"<p class='{classname}'>{content}</p>" if classname else f"<p>{content}</p>"
19
+
20
+
21
+ def get_exif_data(image):
22
+ items = image.info
23
+
24
+ info = ''
25
+ for key, text in items.items():
26
+ info += f"""
27
+ <div>
28
+ <p><b>{plaintext_to_html(str(key))}</b></p>
29
+ <p>{plaintext_to_html(str(text))}</p>
30
+ </div>
31
+ """.strip() + "\n"
32
+
33
+ if len(info) == 0:
34
+ message = "Nothing found in the image."
35
+ info = f"<div><p>{message}<p></div>"
36
+
37
+ return info
38
+
39
+
40
+ with gr.Row():
41
+ with gr.Column():
42
+ image_input = gr.Image(type="pil")
43
+
44
+ with gr.Column():
45
+ exif_output = gr.HTML(label="EXIF Data")
46
+
47
+ image_input.upload(get_exif_data, inputs=[image_input], outputs=exif_output)
48
+
49
+
50
+ demo.launch()