Spaces:
Runtime error
Runtime error
Commit
·
bd32e71
1
Parent(s):
90cb8f1
Update app.py
Browse files
app.py
CHANGED
|
@@ -67,16 +67,70 @@ def run_lora(prompt, selected_state, progress=gr.Progress(track_tqdm=True)):
|
|
| 67 |
logging.error(f"API Error: {response.status_code}")
|
| 68 |
raise gr.Error("API Error: Unable to fetch the image.") # Raise a Gradio error here
|
| 69 |
|
| 70 |
-
def
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 71 |
processed_image = image.copy()
|
|
|
|
| 72 |
if downscale > 1:
|
| 73 |
processed_image = downscale_image(processed_image, downscale)
|
| 74 |
-
|
| 75 |
-
|
| 76 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 77 |
processed_image = convert_to_grayscale(processed_image)
|
| 78 |
-
|
| 79 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 80 |
return processed_image
|
| 81 |
|
| 82 |
with gr.Blocks() as app:
|
|
|
|
| 67 |
logging.error(f"API Error: {response.status_code}")
|
| 68 |
raise gr.Error("API Error: Unable to fetch the image.") # Raise a Gradio error here
|
| 69 |
|
| 70 |
+
def postprocess(
|
| 71 |
+
image,
|
| 72 |
+
enabled,
|
| 73 |
+
downscale,
|
| 74 |
+
need_rescale,
|
| 75 |
+
enable_color_limit,
|
| 76 |
+
number_of_colors,
|
| 77 |
+
quantization_method,
|
| 78 |
+
dither_method,
|
| 79 |
+
use_k_means,
|
| 80 |
+
is_grayscale,
|
| 81 |
+
number_of_shades,
|
| 82 |
+
quantization_method_grayscale,
|
| 83 |
+
dither_method_grayscale,
|
| 84 |
+
use_k_means_grayscale,
|
| 85 |
+
is_black_and_white,
|
| 86 |
+
is_inversed_black_and_white,
|
| 87 |
+
black_and_white_threshold,
|
| 88 |
+
use_color_palette,
|
| 89 |
+
palette_image,
|
| 90 |
+
palette_colors,
|
| 91 |
+
dither_method_palette
|
| 92 |
+
):
|
| 93 |
+
if not enabled:
|
| 94 |
+
return image
|
| 95 |
+
|
| 96 |
processed_image = image.copy()
|
| 97 |
+
|
| 98 |
if downscale > 1:
|
| 99 |
processed_image = downscale_image(processed_image, downscale)
|
| 100 |
+
|
| 101 |
+
if enable_color_limit:
|
| 102 |
+
processed_image = limit_colors(
|
| 103 |
+
image=processed_image,
|
| 104 |
+
limit=number_of_colors,
|
| 105 |
+
quantize=QUANTIZATION_METHODS[quantization_method],
|
| 106 |
+
dither=DITHER_METHODS[dither_method],
|
| 107 |
+
use_k_means=use_k_means
|
| 108 |
+
)
|
| 109 |
+
|
| 110 |
+
if is_grayscale:
|
| 111 |
processed_image = convert_to_grayscale(processed_image)
|
| 112 |
+
processed_image = limit_colors(
|
| 113 |
+
image=processed_image,
|
| 114 |
+
limit=number_of_shades,
|
| 115 |
+
quantize=QUANTIZATION_METHODS[quantization_method_grayscale],
|
| 116 |
+
dither=DITHER_METHODS[dither_method_grayscale],
|
| 117 |
+
use_k_means=use_k_means_grayscale
|
| 118 |
+
)
|
| 119 |
+
|
| 120 |
+
if is_black_and_white:
|
| 121 |
+
processed_image = convert_to_black_and_white(processed_image, black_and_white_threshold, is_inversed_black_and_white)
|
| 122 |
+
|
| 123 |
+
if use_color_palette:
|
| 124 |
+
processed_image = limit_colors(
|
| 125 |
+
image=processed_image,
|
| 126 |
+
palette=palette_image,
|
| 127 |
+
palette_colors=palette_colors,
|
| 128 |
+
dither=DITHER_METHODS[dither_method_palette]
|
| 129 |
+
)
|
| 130 |
+
|
| 131 |
+
if need_rescale:
|
| 132 |
+
processed_image = resize_image(processed_image, image.size)
|
| 133 |
+
|
| 134 |
return processed_image
|
| 135 |
|
| 136 |
with gr.Blocks() as app:
|