tlam
commited on
Commit
·
31fe7cc
1
Parent(s):
564378d
Comfy
Browse files- .DS_Store +0 -0
- .gitignore +2 -1
- app.py +31 -4
.DS_Store
CHANGED
Binary files a/.DS_Store and b/.DS_Store differ
|
|
.gitignore
CHANGED
@@ -1 +1,2 @@
|
|
1 |
-
/venv
|
|
|
|
1 |
+
/venv
|
2 |
+
.DS_Store
|
app.py
CHANGED
@@ -26,6 +26,9 @@ def extract_metadata(image_file):
|
|
26 |
negative_prompt = 'N/A'
|
27 |
adetailer_prompt_1 = 'N/A'
|
28 |
adetailer_prompt_2 = 'N/A'
|
|
|
|
|
|
|
29 |
|
30 |
# Convert the entire metadata dictionary to a readable string
|
31 |
metadata_str = "\n".join([f"{key}: {value}" for key, value in metadata.items()])
|
@@ -64,22 +67,41 @@ def extract_metadata(image_file):
|
|
64 |
if seed_match:
|
65 |
seed_number = seed_match.group(1).strip()
|
66 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
67 |
else:
|
68 |
# No 'parameters' field in metadata
|
69 |
prompt = 'N/A'
|
70 |
|
71 |
# Return the outputs, replacing 'original_metadata_output' with 'metadata_str'
|
72 |
-
return
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
73 |
|
74 |
# Create the Gradio interface
|
75 |
with gr.Blocks() as iface:
|
76 |
gr.Markdown("# Image Metadata Extractor")
|
77 |
gr.Markdown("Upload an image (PNG, JPEG, TIFF) to extract its metadata and parse it for prompts.")
|
78 |
-
|
79 |
with gr.Row():
|
80 |
with gr.Column(): # First column for image upload and preview
|
81 |
image_input = gr.File(label="Upload Image", type="filepath")
|
82 |
image_output = gr.Image(label="Image Preview")
|
|
|
83 |
|
84 |
with gr.Column(): # Second column for metadata outputs
|
85 |
prompt_output = gr.Textbox(label="Prompt", lines=4, show_copy_button=True)
|
@@ -87,8 +109,11 @@ with gr.Blocks() as iface:
|
|
87 |
seed_output = gr.Textbox(label="Seed Number", lines=1, show_copy_button=True)
|
88 |
adetailer_prompt_1_output = gr.Textbox(label="ADetailer Prompt 1", lines=3, show_copy_button=True)
|
89 |
adetailer_prompt_2_output = gr.Textbox(label="ADetailer Prompt 2", lines=3, show_copy_button=True)
|
90 |
-
|
91 |
-
|
|
|
|
|
|
|
92 |
|
93 |
# Set up the input-output relationships
|
94 |
image_input.change(
|
@@ -102,6 +127,8 @@ with gr.Blocks() as iface:
|
|
102 |
adetailer_prompt_1_output,
|
103 |
adetailer_prompt_2_output,
|
104 |
original_metadata_output,
|
|
|
|
|
105 |
]
|
106 |
)
|
107 |
|
|
|
26 |
negative_prompt = 'N/A'
|
27 |
adetailer_prompt_1 = 'N/A'
|
28 |
adetailer_prompt_2 = 'N/A'
|
29 |
+
seed_number = -1
|
30 |
+
comfy_prompt = 'N/A'
|
31 |
+
comfy_workflow = 'N/A'
|
32 |
|
33 |
# Convert the entire metadata dictionary to a readable string
|
34 |
metadata_str = "\n".join([f"{key}: {value}" for key, value in metadata.items()])
|
|
|
67 |
if seed_match:
|
68 |
seed_number = seed_match.group(1).strip()
|
69 |
|
70 |
+
# Extract additional metadata fields directly if they exist
|
71 |
+
if 'prompt' in metadata:
|
72 |
+
comfy_prompt = metadata['prompt'].strip()
|
73 |
+
|
74 |
+
if 'workflow' in metadata:
|
75 |
+
comfy_workflow = metadata['workflow'].strip()
|
76 |
+
|
77 |
else:
|
78 |
# No 'parameters' field in metadata
|
79 |
prompt = 'N/A'
|
80 |
|
81 |
# Return the outputs, replacing 'original_metadata_output' with 'metadata_str'
|
82 |
+
return (
|
83 |
+
img_display,
|
84 |
+
prompt,
|
85 |
+
negative_prompt,
|
86 |
+
seed_number,
|
87 |
+
adetailer_prompt_1,
|
88 |
+
adetailer_prompt_2,
|
89 |
+
metadata_str,
|
90 |
+
comfy_prompt,
|
91 |
+
comfy_workflow
|
92 |
+
)
|
93 |
+
|
94 |
+
|
95 |
|
96 |
# Create the Gradio interface
|
97 |
with gr.Blocks() as iface:
|
98 |
gr.Markdown("# Image Metadata Extractor")
|
99 |
gr.Markdown("Upload an image (PNG, JPEG, TIFF) to extract its metadata and parse it for prompts.")
|
|
|
100 |
with gr.Row():
|
101 |
with gr.Column(): # First column for image upload and preview
|
102 |
image_input = gr.File(label="Upload Image", type="filepath")
|
103 |
image_output = gr.Image(label="Image Preview")
|
104 |
+
original_metadata_output = gr.Textbox(label="Original Metadata", lines=20)
|
105 |
|
106 |
with gr.Column(): # Second column for metadata outputs
|
107 |
prompt_output = gr.Textbox(label="Prompt", lines=4, show_copy_button=True)
|
|
|
109 |
seed_output = gr.Textbox(label="Seed Number", lines=1, show_copy_button=True)
|
110 |
adetailer_prompt_1_output = gr.Textbox(label="ADetailer Prompt 1", lines=3, show_copy_button=True)
|
111 |
adetailer_prompt_2_output = gr.Textbox(label="ADetailer Prompt 2", lines=3, show_copy_button=True)
|
112 |
+
with gr.Column(): # Second column for metadata outputs
|
113 |
+
with gr.Row():
|
114 |
+
comfy_prompt_output = gr.Textbox(label="Comfy Prompt", lines=20)
|
115 |
+
with gr.Row():
|
116 |
+
comfy_workflow_output = gr.Textbox(label="Comfy Workflow", lines=20)
|
117 |
|
118 |
# Set up the input-output relationships
|
119 |
image_input.change(
|
|
|
127 |
adetailer_prompt_1_output,
|
128 |
adetailer_prompt_2_output,
|
129 |
original_metadata_output,
|
130 |
+
comfy_prompt_output,
|
131 |
+
comfy_workflow_output,
|
132 |
]
|
133 |
)
|
134 |
|