Spaces:
Runtime error
Runtime error
update sketchpad dimensions
Browse files- app.py +23 -1
- modules/image_utils.py +22 -9
app.py
CHANGED
|
@@ -619,12 +619,22 @@ def replace_input_with_sketch_image(sketch_image):
|
|
| 619 |
def on_input_image_change(image_path):
|
| 620 |
if image_path is None:
|
| 621 |
gr.Warning("Please upload an Input Image to get started.")
|
| 622 |
-
return None,
|
| 623 |
img, img_path = convert_to_rgba_png(image_path)
|
| 624 |
with Image.open(img_path) as pil_img:
|
| 625 |
width, height = pil_img.size
|
| 626 |
return [img_path, gr.update(width=width, height=height)]
|
| 627 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 628 |
@spaces.GPU()
|
| 629 |
def getVersions():
|
| 630 |
return versions_html()
|
|
@@ -919,6 +929,10 @@ with gr.Blocks(css_paths="style_20250128.css", title=title, theme='Surn/beeuty',
|
|
| 919 |
fn=run_lora,
|
| 920 |
inputs=[prompt, map_options, input_image, image_strength, cfg_scale, steps, selected_index, randomize_seed, seed, width, height, lora_scale, enlarge_to_default, gr.State(True)],
|
| 921 |
outputs=[input_image, seed, progress_bar], scroll_to_output=True
|
|
|
|
|
|
|
|
|
|
|
|
|
| 922 |
)
|
| 923 |
prerendered_image_gallery.select(
|
| 924 |
fn=on_prerendered_gallery_selection,
|
|
@@ -942,6 +956,10 @@ with gr.Blocks(css_paths="style_20250128.css", title=title, theme='Surn/beeuty',
|
|
| 942 |
lambda: current_prerendered_image.value,
|
| 943 |
inputs=None,
|
| 944 |
outputs=[input_image], scroll_to_output=True
|
|
|
|
|
|
|
|
|
|
|
|
|
| 945 |
)
|
| 946 |
lora_gallery.select(
|
| 947 |
update_selection,
|
|
@@ -962,6 +980,10 @@ with gr.Blocks(css_paths="style_20250128.css", title=title, theme='Surn/beeuty',
|
|
| 962 |
fn=run_lora,
|
| 963 |
inputs=[prompt, map_options, input_image, image_strength, cfg_scale, steps, selected_index, randomize_seed, seed, width, height, lora_scale, enlarge_to_default, gr.State(False)],
|
| 964 |
outputs=[input_image, seed, progress_bar]
|
|
|
|
|
|
|
|
|
|
|
|
|
| 965 |
)
|
| 966 |
|
| 967 |
load_env_vars(dotenv_path)
|
|
|
|
| 619 |
def on_input_image_change(image_path):
|
| 620 |
if image_path is None:
|
| 621 |
gr.Warning("Please upload an Input Image to get started.")
|
| 622 |
+
return None, gr.update()
|
| 623 |
img, img_path = convert_to_rgba_png(image_path)
|
| 624 |
with Image.open(img_path) as pil_img:
|
| 625 |
width, height = pil_img.size
|
| 626 |
return [img_path, gr.update(width=width, height=height)]
|
| 627 |
|
| 628 |
+
def update_sketch_dimensions(input_image, sketch_image):
|
| 629 |
+
# Load the images using open_image() if they are provided as file paths.
|
| 630 |
+
in_img = open_image(input_image) if isinstance(input_image, str) else input_image
|
| 631 |
+
sk_img_path, _ = get_image_from_dict(sketch_image)
|
| 632 |
+
sk_img = open_image(sk_img_path)
|
| 633 |
+
# Resize sketch image if dimensions don't match input image.
|
| 634 |
+
if in_img.size != sk_img.size:
|
| 635 |
+
sk_img = sk_img.resize(in_img.size, Image.LANCZOS)
|
| 636 |
+
return sk_img
|
| 637 |
+
|
| 638 |
@spaces.GPU()
|
| 639 |
def getVersions():
|
| 640 |
return versions_html()
|
|
|
|
| 929 |
fn=run_lora,
|
| 930 |
inputs=[prompt, map_options, input_image, image_strength, cfg_scale, steps, selected_index, randomize_seed, seed, width, height, lora_scale, enlarge_to_default, gr.State(True)],
|
| 931 |
outputs=[input_image, seed, progress_bar], scroll_to_output=True
|
| 932 |
+
).then(
|
| 933 |
+
fn=update_sketch_dimensions,
|
| 934 |
+
inputs=[input_image, sketch_image],
|
| 935 |
+
outputs=[sketch_image]
|
| 936 |
)
|
| 937 |
prerendered_image_gallery.select(
|
| 938 |
fn=on_prerendered_gallery_selection,
|
|
|
|
| 956 |
lambda: current_prerendered_image.value,
|
| 957 |
inputs=None,
|
| 958 |
outputs=[input_image], scroll_to_output=True
|
| 959 |
+
).then(
|
| 960 |
+
fn=update_sketch_dimensions,
|
| 961 |
+
inputs=[input_image, sketch_image],
|
| 962 |
+
outputs=[sketch_image]
|
| 963 |
)
|
| 964 |
lora_gallery.select(
|
| 965 |
update_selection,
|
|
|
|
| 980 |
fn=run_lora,
|
| 981 |
inputs=[prompt, map_options, input_image, image_strength, cfg_scale, steps, selected_index, randomize_seed, seed, width, height, lora_scale, enlarge_to_default, gr.State(False)],
|
| 982 |
outputs=[input_image, seed, progress_bar]
|
| 983 |
+
).then(
|
| 984 |
+
fn=update_sketch_dimensions,
|
| 985 |
+
inputs=[input_image, sketch_image],
|
| 986 |
+
outputs=[sketch_image]
|
| 987 |
)
|
| 988 |
|
| 989 |
load_env_vars(dotenv_path)
|
modules/image_utils.py
CHANGED
|
@@ -95,21 +95,34 @@ def build_prerendered_images(images_list):
|
|
| 95 |
# Example usage
|
| 96 |
# filtered_maps = get_maps_with_quality_less_than(3)
|
| 97 |
# print(filtered_maps)
|
| 98 |
-
def build_prerendered_images_by_quality(quality_limit,key='file'):
|
| 99 |
"""
|
| 100 |
-
Retrieve
|
| 101 |
-
|
|
|
|
| 102 |
Args:
|
| 103 |
-
|
| 104 |
-
|
|
|
|
| 105 |
Returns:
|
| 106 |
-
list: A list of file paths meeting the quality criteria.
|
| 107 |
-
"""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 108 |
images_list = [
|
| 109 |
-
map_info[key]
|
| 110 |
-
for map_info in
|
| 111 |
if map_info['quality'] <= quality_limit
|
| 112 |
]
|
|
|
|
| 113 |
return build_prerendered_images(images_list)
|
| 114 |
|
| 115 |
|
|
|
|
| 95 |
# Example usage
|
| 96 |
# filtered_maps = get_maps_with_quality_less_than(3)
|
| 97 |
# print(filtered_maps)
|
| 98 |
+
def build_prerendered_images_by_quality(quality_limit, key='file'):
|
| 99 |
"""
|
| 100 |
+
Retrieve and sort file paths from PRE_RENDERED_MAPS_JSON_LEVELS where quality is less than or equal to the given limit.
|
| 101 |
+
The sorting order matches pre_rendered_maps_paths based on quality and a case-insensitive alphanumeric key.
|
| 102 |
+
|
| 103 |
Args:
|
| 104 |
+
quality_limit (int): The quality threshold.
|
| 105 |
+
key (str): The key to extract the file path from each map info (default is 'file').
|
| 106 |
+
|
| 107 |
Returns:
|
| 108 |
+
list: A list of sorted file paths meeting the quality criteria.
|
| 109 |
+
"""
|
| 110 |
+
# Sort the PRE_RENDERED_MAPS_JSON_LEVELS items by quality and alphanumeric key
|
| 111 |
+
sorted_maps = sorted(
|
| 112 |
+
PRE_RENDERED_MAPS_JSON_LEVELS.items(),
|
| 113 |
+
key=lambda x: (
|
| 114 |
+
x[1]['quality'],
|
| 115 |
+
''.join(char.lower() for char in x[0] if char.isalnum())
|
| 116 |
+
)
|
| 117 |
+
)
|
| 118 |
+
|
| 119 |
+
# Filter and extract the file paths that meet the quality limit
|
| 120 |
images_list = [
|
| 121 |
+
map_info[key].replace("\\", "/")
|
| 122 |
+
for _, map_info in sorted_maps
|
| 123 |
if map_info['quality'] <= quality_limit
|
| 124 |
]
|
| 125 |
+
|
| 126 |
return build_prerendered_images(images_list)
|
| 127 |
|
| 128 |
|