Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -149,6 +149,31 @@ def upscale_image(image, model_selection: str, progress=gr.Progress(track_tqdm=T
|
|
| 149 |
print(f"An error occurred: {traceback.format_exc()}")
|
| 150 |
raise gr.Error(f"An error occurred during processing: {e}")
|
| 151 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 152 |
def clear_outputs():
|
| 153 |
return None, None
|
| 154 |
|
|
@@ -172,6 +197,7 @@ with gr.Blocks(delete_cache=(3600, 3600)) as demo:
|
|
| 172 |
label="Model (alphabetically sorted)",
|
| 173 |
)
|
| 174 |
run_button = gr.Button("Upscale", variant="primary")
|
|
|
|
| 175 |
|
| 176 |
with gr.Column(scale=2):
|
| 177 |
result_slider = ImageSlider(
|
|
@@ -188,6 +214,17 @@ with gr.Blocks(delete_cache=(3600, 3600)) as demo:
|
|
| 188 |
)
|
| 189 |
|
| 190 |
download_output = gr.File(label="Download Full-Quality Upscaled Image (Lossless PNG)")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 191 |
|
| 192 |
# --- Event Handling ---
|
| 193 |
run_button.click(
|
|
@@ -200,6 +237,12 @@ with gr.Blocks(delete_cache=(3600, 3600)) as demo:
|
|
| 200 |
inputs=[input_image, model_selection],
|
| 201 |
outputs=[result_slider, download_output],
|
| 202 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 203 |
|
| 204 |
# --- Pre-load the default model for a faster first-time user experience ---
|
| 205 |
try:
|
|
|
|
| 149 |
print(f"An error occurred: {traceback.format_exc()}")
|
| 150 |
raise gr.Error(f"An error occurred during processing: {e}")
|
| 151 |
|
| 152 |
+
@spaces.GPU
|
| 153 |
+
def upscale_with_all_models(image, progress=gr.Progress(track_tqdm=True)):
|
| 154 |
+
"""Upscale image with all available models and return results as a list."""
|
| 155 |
+
if image is None:
|
| 156 |
+
raise gr.Error("No image uploaded. Please upload an image to upscale.")
|
| 157 |
+
|
| 158 |
+
try:
|
| 159 |
+
original = load_image(image)
|
| 160 |
+
all_results = []
|
| 161 |
+
total_models = len(MODELS)
|
| 162 |
+
|
| 163 |
+
for idx, (model_name, _) in enumerate(MODELS.items()):
|
| 164 |
+
progress(idx / total_models, desc=f"Upscaling with {model_name}... ({idx + 1}/{total_models})")
|
| 165 |
+
print(f"Processing with model: {model_name}")
|
| 166 |
+
upscaler = get_upscaler(model_name)
|
| 167 |
+
upscaled = upscaler(original, tiling=True, tile_width=1024, tile_height=1024)
|
| 168 |
+
all_results.append((upscaled, model_name))
|
| 169 |
+
|
| 170 |
+
progress(1.0, desc="All upscaling complete!")
|
| 171 |
+
return all_results
|
| 172 |
+
|
| 173 |
+
except Exception as e:
|
| 174 |
+
print(f"An error occurred: {traceback.format_exc()}")
|
| 175 |
+
raise gr.Error(f"An error occurred during processing: {e}")
|
| 176 |
+
|
| 177 |
def clear_outputs():
|
| 178 |
return None, None
|
| 179 |
|
|
|
|
| 197 |
label="Model (alphabetically sorted)",
|
| 198 |
)
|
| 199 |
run_button = gr.Button("Upscale", variant="primary")
|
| 200 |
+
run_all_button = gr.Button("Upscale with All Models", variant="secondary")
|
| 201 |
|
| 202 |
with gr.Column(scale=2):
|
| 203 |
result_slider = ImageSlider(
|
|
|
|
| 214 |
)
|
| 215 |
|
| 216 |
download_output = gr.File(label="Download Full-Quality Upscaled Image (Lossless PNG)")
|
| 217 |
+
|
| 218 |
+
# --- Gallery for all models ---
|
| 219 |
+
all_models_gallery = gr.Gallery(
|
| 220 |
+
label="All Models Results",
|
| 221 |
+
show_label=True,
|
| 222 |
+
elem_id="gallery",
|
| 223 |
+
columns=2,
|
| 224 |
+
rows=2,
|
| 225 |
+
object_fit="scale-down",
|
| 226 |
+
show_download_button=True
|
| 227 |
+
)
|
| 228 |
|
| 229 |
# --- Event Handling ---
|
| 230 |
run_button.click(
|
|
|
|
| 237 |
inputs=[input_image, model_selection],
|
| 238 |
outputs=[result_slider, download_output],
|
| 239 |
)
|
| 240 |
+
|
| 241 |
+
run_all_button.click(
|
| 242 |
+
fn=upscale_with_all_models,
|
| 243 |
+
inputs=[input_image],
|
| 244 |
+
outputs=[all_models_gallery],
|
| 245 |
+
)
|
| 246 |
|
| 247 |
# --- Pre-load the default model for a faster first-time user experience ---
|
| 248 |
try:
|