Spaces:
Runtime error
Runtime error
rollback app.py, change text metadata at utils to parameters
Browse files
app.py
CHANGED
@@ -107,7 +107,7 @@ def generate(
|
|
107 |
|
108 |
if use_upscaler:
|
109 |
upscaler_pipe = StableDiffusionXLImg2ImgPipeline(**pipe.components)
|
110 |
-
|
111 |
"prompt": prompt,
|
112 |
"negative_prompt": negative_prompt,
|
113 |
"resolution": f"{width} x {height}",
|
@@ -123,20 +123,20 @@ def generate(
|
|
123 |
if use_upscaler:
|
124 |
new_width = int(width * upscale_by)
|
125 |
new_height = int(height * upscale_by)
|
126 |
-
|
127 |
"upscale_method": "nearest-exact",
|
128 |
"upscaler_strength": upscaler_strength,
|
129 |
"upscale_by": upscale_by,
|
130 |
"new_resolution": f"{new_width} x {new_height}",
|
131 |
}
|
132 |
else:
|
133 |
-
|
134 |
-
|
135 |
"Model": DESCRIPTION,
|
136 |
"Model hash": "e3c47aedb0",
|
137 |
}
|
138 |
|
139 |
-
logger.info(json.dumps(
|
140 |
|
141 |
try:
|
142 |
if use_upscaler:
|
@@ -175,14 +175,14 @@ def generate(
|
|
175 |
|
176 |
if images:
|
177 |
image_paths = [
|
178 |
-
utils.save_image(image,
|
179 |
for image in images
|
180 |
]
|
181 |
|
182 |
for image_path in image_paths:
|
183 |
logger.info(f"Image saved as {image_path} with metadata")
|
184 |
|
185 |
-
return image_paths,
|
186 |
except Exception as e:
|
187 |
logger.exception(f"An error occurred: {e}")
|
188 |
raise
|
@@ -334,11 +334,11 @@ with gr.Blocks(css="style.css", theme="NoCrypt/miku@1.2.1") as demo:
|
|
334 |
show_label=False
|
335 |
)
|
336 |
with gr.Accordion(label="Generation Parameters", open=False):
|
337 |
-
|
338 |
gr.Examples(
|
339 |
examples=config.examples,
|
340 |
inputs=prompt,
|
341 |
-
outputs=[result,
|
342 |
fn=lambda *args, **kwargs: generate(*args, use_upscaler=True, **kwargs),
|
343 |
cache_examples=CACHE_EXAMPLES,
|
344 |
)
|
@@ -387,7 +387,7 @@ with gr.Blocks(css="style.css", theme="NoCrypt/miku@1.2.1") as demo:
|
|
387 |
upscale_by,
|
388 |
add_quality_tags,
|
389 |
],
|
390 |
-
outputs=[result,
|
391 |
api_name="run",
|
392 |
)
|
393 |
|
|
|
107 |
|
108 |
if use_upscaler:
|
109 |
upscaler_pipe = StableDiffusionXLImg2ImgPipeline(**pipe.components)
|
110 |
+
metadata = {
|
111 |
"prompt": prompt,
|
112 |
"negative_prompt": negative_prompt,
|
113 |
"resolution": f"{width} x {height}",
|
|
|
123 |
if use_upscaler:
|
124 |
new_width = int(width * upscale_by)
|
125 |
new_height = int(height * upscale_by)
|
126 |
+
metadata["use_upscaler"] = {
|
127 |
"upscale_method": "nearest-exact",
|
128 |
"upscaler_strength": upscaler_strength,
|
129 |
"upscale_by": upscale_by,
|
130 |
"new_resolution": f"{new_width} x {new_height}",
|
131 |
}
|
132 |
else:
|
133 |
+
metadata["use_upscaler"] = None
|
134 |
+
metadata["Model"] = {
|
135 |
"Model": DESCRIPTION,
|
136 |
"Model hash": "e3c47aedb0",
|
137 |
}
|
138 |
|
139 |
+
logger.info(json.dumps(metadata, indent=4))
|
140 |
|
141 |
try:
|
142 |
if use_upscaler:
|
|
|
175 |
|
176 |
if images:
|
177 |
image_paths = [
|
178 |
+
utils.save_image(image, metadata, OUTPUT_DIR, IS_COLAB)
|
179 |
for image in images
|
180 |
]
|
181 |
|
182 |
for image_path in image_paths:
|
183 |
logger.info(f"Image saved as {image_path} with metadata")
|
184 |
|
185 |
+
return image_paths, metadata
|
186 |
except Exception as e:
|
187 |
logger.exception(f"An error occurred: {e}")
|
188 |
raise
|
|
|
334 |
show_label=False
|
335 |
)
|
336 |
with gr.Accordion(label="Generation Parameters", open=False):
|
337 |
+
gr_metadata = gr.JSON(label="metadata", show_label=False)
|
338 |
gr.Examples(
|
339 |
examples=config.examples,
|
340 |
inputs=prompt,
|
341 |
+
outputs=[result, gr_metadata],
|
342 |
fn=lambda *args, **kwargs: generate(*args, use_upscaler=True, **kwargs),
|
343 |
cache_examples=CACHE_EXAMPLES,
|
344 |
)
|
|
|
387 |
upscale_by,
|
388 |
add_quality_tags,
|
389 |
],
|
390 |
+
outputs=[result, gr_metadata],
|
391 |
api_name="run",
|
392 |
)
|
393 |
|
utils.py
CHANGED
@@ -169,7 +169,7 @@ def save_image(image, metadata, output_dir, is_colab):
|
|
169 |
filepath = os.path.join(output_dir, filename)
|
170 |
metadata_str = json.dumps(metadata)
|
171 |
info = PngImagePlugin.PngInfo()
|
172 |
-
info.add_text("
|
173 |
image.save(filepath, "PNG", pnginfo=info)
|
174 |
return filepath
|
175 |
|
|
|
169 |
filepath = os.path.join(output_dir, filename)
|
170 |
metadata_str = json.dumps(metadata)
|
171 |
info = PngImagePlugin.PngInfo()
|
172 |
+
info.add_text("parameters", metadata_str)
|
173 |
image.save(filepath, "PNG", pnginfo=info)
|
174 |
return filepath
|
175 |
|