Upload 7 files
Browse files- .gitattributes +5 -0
- README.md +6 -5
- app.py +89 -0
- example/arimakana.png +3 -0
- example/asukatest.png +3 -0
- example/shinji.png +3 -0
- example/stelle.png +3 -0
.gitattributes
CHANGED
@@ -33,3 +33,8 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
|
33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
|
|
|
|
|
|
|
|
|
|
|
33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
36 |
+
example/asukatest.png filter=lfs diff=lfs merge=lfs -text
|
37 |
+
example/cagliostro.png filter=lfs diff=lfs merge=lfs -text
|
38 |
+
example/stelle.png filter=lfs diff=lfs merge=lfs -text
|
39 |
+
arimakana.png filter=lfs diff=lfs merge=lfs -text
|
40 |
+
example/shinji.png filter=lfs diff=lfs merge=lfs -text
|
README.md
CHANGED
@@ -1,12 +1,13 @@
|
|
1 |
---
|
2 |
-
title:
|
3 |
-
emoji:
|
4 |
-
colorFrom:
|
5 |
-
colorTo:
|
6 |
sdk: gradio
|
7 |
sdk_version: 4.22.0
|
8 |
app_file: app.py
|
9 |
pinned: false
|
|
|
10 |
---
|
11 |
|
12 |
-
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
|
|
1 |
---
|
2 |
+
title: PNGInfo
|
3 |
+
emoji: π
|
4 |
+
colorFrom: gray
|
5 |
+
colorTo: gray
|
6 |
sdk: gradio
|
7 |
sdk_version: 4.22.0
|
8 |
app_file: app.py
|
9 |
pinned: false
|
10 |
+
short_description: Extract and display metadata from AI generated images
|
11 |
---
|
12 |
|
13 |
+
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
app.py
ADDED
@@ -0,0 +1,89 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from PIL import Image, PngImagePlugin
|
3 |
+
import json
|
4 |
+
import traceback
|
5 |
+
|
6 |
+
def extract_metadata(image):
|
7 |
+
if image is None:
|
8 |
+
return "Please upload an image.", {}
|
9 |
+
|
10 |
+
try:
|
11 |
+
metadata = {}
|
12 |
+
if 'metadata' in image.info:
|
13 |
+
metadata = json.loads(image.info['metadata'])
|
14 |
+
elif 'prompt' in image.info:
|
15 |
+
metadata = json.loads(image.info['prompt'])
|
16 |
+
elif 'Comment' in image.info:
|
17 |
+
metadata = json.loads(image.info['Comment'])
|
18 |
+
metadata['model'] = 'NovelAI'
|
19 |
+
elif 'parameters' in image.info:
|
20 |
+
if image.info['parameters'].startswith('{'):
|
21 |
+
parameters_data = json.loads(image.info['parameters'])
|
22 |
+
if 'sui_image_params' in parameters_data:
|
23 |
+
sui_image_params = parameters_data['sui_image_params']
|
24 |
+
metadata.update(sui_image_params)
|
25 |
+
else:
|
26 |
+
lines = image.info['parameters'].split('\n')
|
27 |
+
prompt = lines[0].strip()
|
28 |
+
negative_prompt = lines[1].strip().replace('Negative prompt:', '').strip()
|
29 |
+
metadata['prompt'] = prompt
|
30 |
+
metadata['negative_prompt'] = negative_prompt
|
31 |
+
|
32 |
+
for line in lines[2:]:
|
33 |
+
line = line.strip()
|
34 |
+
if line.startswith('Steps:'):
|
35 |
+
steps_info = line.split(':', 1)[1].strip().split(',')
|
36 |
+
for info in steps_info:
|
37 |
+
info = info.strip()
|
38 |
+
if ':' in info:
|
39 |
+
key, value = info.split(':', 1)
|
40 |
+
metadata[key.strip()] = value.strip()
|
41 |
+
else:
|
42 |
+
return "No supported metadata found in the image.", {}
|
43 |
+
|
44 |
+
return "Metadata extracted successfully.", metadata
|
45 |
+
except Exception as e:
|
46 |
+
error_message = f"Error extracting metadata: {str(e)}\n{traceback.format_exc()}"
|
47 |
+
return error_message, {}
|
48 |
+
|
49 |
+
def process_image(image):
|
50 |
+
status, metadata = extract_metadata(image)
|
51 |
+
return status, metadata
|
52 |
+
|
53 |
+
with gr.Blocks() as demo:
|
54 |
+
gr.Markdown(
|
55 |
+
"""
|
56 |
+
# Image Metadata Extractor
|
57 |
+
Extract and display metadata from images generated by various AI tools.
|
58 |
+
"""
|
59 |
+
)
|
60 |
+
|
61 |
+
with gr.Row():
|
62 |
+
with gr.Column():
|
63 |
+
input_image = gr.Image(label="Input Image", type="pil", height=480)
|
64 |
+
|
65 |
+
with gr.Column():
|
66 |
+
status_output = gr.Textbox(label="Status")
|
67 |
+
output_metadata = gr.JSON(label="Metadata")
|
68 |
+
|
69 |
+
input_image.change(
|
70 |
+
fn=process_image,
|
71 |
+
inputs=input_image,
|
72 |
+
outputs=[status_output, output_metadata],
|
73 |
+
api_name="interrogate"
|
74 |
+
)
|
75 |
+
|
76 |
+
gr.Examples(
|
77 |
+
examples=[
|
78 |
+
["example/asukatest.png"],
|
79 |
+
["example/arimakana.png"],
|
80 |
+
["example/stelle.png"],
|
81 |
+
["example/shinji.png"],
|
82 |
+
],
|
83 |
+
inputs=input_image,
|
84 |
+
outputs=[status_output, output_metadata],
|
85 |
+
fn=process_image,
|
86 |
+
cache_examples=True,
|
87 |
+
)
|
88 |
+
|
89 |
+
demo.launch()
|
example/arimakana.png
ADDED
Git LFS Details
|
example/asukatest.png
ADDED
Git LFS Details
|
example/shinji.png
ADDED
Git LFS Details
|
example/stelle.png
ADDED
Git LFS Details
|