Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -23,11 +23,10 @@ def extract_parameters(image, show_full_metadata=False):
|
|
23 |
try:
|
24 |
# Parse as JSON if possible
|
25 |
prompt_data = json.loads(raw_prompt)
|
26 |
-
# Look for the main prompt text
|
27 |
main_prompt = None
|
28 |
for node_id, node in prompt_data.items():
|
29 |
if "inputs" in node and "text" in node["inputs"]:
|
30 |
-
# Prioritize nodes with meaningful text input
|
31 |
text = node["inputs"]["text"]
|
32 |
if isinstance(text, str) and text.strip():
|
33 |
main_prompt = text
|
@@ -37,7 +36,6 @@ def extract_parameters(image, show_full_metadata=False):
|
|
37 |
main_prompt = "No clear prompt found in workflow."
|
38 |
|
39 |
if show_full_metadata:
|
40 |
-
# Format full metadata with spacing
|
41 |
full_output = "Full Workflow Metadata:\n\n"
|
42 |
for node_id, node in prompt_data.items():
|
43 |
full_output += f"Node {node_id}:\n"
|
@@ -46,15 +44,12 @@ def extract_parameters(image, show_full_metadata=False):
|
|
46 |
full_output += "\n"
|
47 |
return f"Main Prompt:\n{main_prompt}\n\n{full_output}"
|
48 |
else:
|
49 |
-
# Just the cleaned-up main prompt
|
50 |
return f"Main Prompt:\n{main_prompt}"
|
51 |
except json.JSONDecodeError:
|
52 |
-
# If not JSON, treat as raw text
|
53 |
if show_full_metadata:
|
54 |
return f"Raw Prompt:\n{raw_prompt}\n\nFull Metadata:\n{metadata}"
|
55 |
return f"Main Prompt:\n{raw_prompt}"
|
56 |
else:
|
57 |
-
# No "prompt" key, show all metadata if toggled
|
58 |
if show_full_metadata:
|
59 |
output = "Full Metadata:\n\n"
|
60 |
for key, value in metadata.items():
|
@@ -65,16 +60,23 @@ def extract_parameters(image, show_full_metadata=False):
|
|
65 |
except Exception as e:
|
66 |
return f"Error processing image: {str(e)}"
|
67 |
|
68 |
-
# Define the Gradio interface
|
69 |
interface = gr.Interface(
|
70 |
fn=extract_parameters,
|
71 |
inputs=[
|
72 |
gr.Image(type="filepath", label="Upload a ComfyUI Image"),
|
73 |
-
gr.Checkbox(label="Show Full Metadata", value=False)
|
74 |
],
|
75 |
outputs=gr.Textbox(label="Extracted Parameters", lines=10),
|
76 |
title="ComfyUI Image to Parameters",
|
77 |
-
description=
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
78 |
theme="default"
|
79 |
)
|
80 |
|
|
|
23 |
try:
|
24 |
# Parse as JSON if possible
|
25 |
prompt_data = json.loads(raw_prompt)
|
26 |
+
# Look for the main prompt text
|
27 |
main_prompt = None
|
28 |
for node_id, node in prompt_data.items():
|
29 |
if "inputs" in node and "text" in node["inputs"]:
|
|
|
30 |
text = node["inputs"]["text"]
|
31 |
if isinstance(text, str) and text.strip():
|
32 |
main_prompt = text
|
|
|
36 |
main_prompt = "No clear prompt found in workflow."
|
37 |
|
38 |
if show_full_metadata:
|
|
|
39 |
full_output = "Full Workflow Metadata:\n\n"
|
40 |
for node_id, node in prompt_data.items():
|
41 |
full_output += f"Node {node_id}:\n"
|
|
|
44 |
full_output += "\n"
|
45 |
return f"Main Prompt:\n{main_prompt}\n\n{full_output}"
|
46 |
else:
|
|
|
47 |
return f"Main Prompt:\n{main_prompt}"
|
48 |
except json.JSONDecodeError:
|
|
|
49 |
if show_full_metadata:
|
50 |
return f"Raw Prompt:\n{raw_prompt}\n\nFull Metadata:\n{metadata}"
|
51 |
return f"Main Prompt:\n{raw_prompt}"
|
52 |
else:
|
|
|
53 |
if show_full_metadata:
|
54 |
output = "Full Metadata:\n\n"
|
55 |
for key, value in metadata.items():
|
|
|
60 |
except Exception as e:
|
61 |
return f"Error processing image: {str(e)}"
|
62 |
|
63 |
+
# Define the Gradio interface with attribution
|
64 |
interface = gr.Interface(
|
65 |
fn=extract_parameters,
|
66 |
inputs=[
|
67 |
gr.Image(type="filepath", label="Upload a ComfyUI Image"),
|
68 |
+
gr.Checkbox(label="Show Full Metadata", value=False)
|
69 |
],
|
70 |
outputs=gr.Textbox(label="Extracted Parameters", lines=10),
|
71 |
title="ComfyUI Image to Parameters",
|
72 |
+
description=(
|
73 |
+
"Upload a ComfyUI image to extract its prompt. Toggle 'Show Full Metadata' for the complete workflow.\n\n"
|
74 |
+
"This app is inspired by and adapted from ImagePromptViewer by LordKa-Berlin. "
|
75 |
+
"Original creator: LordKa-Berlin. "
|
76 |
+
"Licensed under CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). "
|
77 |
+
"Source: https://github.com/LordKa-Berlin/ImagePromptViewer. "
|
78 |
+
"Modified by QES for Gradio integration."
|
79 |
+
),
|
80 |
theme="default"
|
81 |
)
|
82 |
|