Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -151,7 +151,7 @@ def upscale_image(image, model_selection: str, progress=gr.Progress(track_tqdm=T
|
|
| 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
|
| 155 |
if image is None:
|
| 156 |
raise gr.Error("No image uploaded. Please upload an image to upscale.")
|
| 157 |
|
|
@@ -165,10 +165,26 @@ def upscale_with_all_models(image, progress=gr.Progress(track_tqdm=True)):
|
|
| 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 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 169 |
|
| 170 |
progress(1.0, desc="All upscaling complete!")
|
| 171 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 172 |
|
| 173 |
except Exception as e:
|
| 174 |
print(f"An error occurred: {traceback.format_exc()}")
|
|
@@ -215,15 +231,8 @@ with gr.Blocks(delete_cache=(3600, 3600)) as demo:
|
|
| 215 |
|
| 216 |
download_output = gr.File(label="Download Full-Quality Upscaled Image (Lossless PNG)")
|
| 217 |
|
| 218 |
-
# ---
|
| 219 |
-
|
| 220 |
-
label="All Models Results",
|
| 221 |
-
show_label=True,
|
| 222 |
-
columns=2,
|
| 223 |
-
rows=1,
|
| 224 |
-
object_fit="scale-down",
|
| 225 |
-
show_download_button=True
|
| 226 |
-
)
|
| 227 |
|
| 228 |
# --- Event Handling ---
|
| 229 |
run_button.click(
|
|
@@ -240,11 +249,7 @@ with gr.Blocks(delete_cache=(3600, 3600)) as demo:
|
|
| 240 |
run_all_button.click(
|
| 241 |
fn=upscale_with_all_models,
|
| 242 |
inputs=[input_image],
|
| 243 |
-
outputs=[
|
| 244 |
-
).then(
|
| 245 |
-
lambda x: x,
|
| 246 |
-
inputs=[all_models_gallery],
|
| 247 |
-
outputs=[all_models_gallery]
|
| 248 |
)
|
| 249 |
|
| 250 |
# --- Pre-load the default model for a faster first-time user experience ---
|
|
|
|
| 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 HTML."""
|
| 155 |
if image is None:
|
| 156 |
raise gr.Error("No image uploaded. Please upload an image to upscale.")
|
| 157 |
|
|
|
|
| 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 |
+
|
| 169 |
+
# Save to temp file
|
| 170 |
+
with tempfile.NamedTemporaryFile(delete=False, suffix=".png") as temp_file:
|
| 171 |
+
upscaled.save(temp_file.name, "PNG")
|
| 172 |
+
all_results.append((temp_file.name, model_name))
|
| 173 |
|
| 174 |
progress(1.0, desc="All upscaling complete!")
|
| 175 |
+
|
| 176 |
+
# Build HTML output with images
|
| 177 |
+
html = '<div style="display: grid; grid-template-columns: repeat(2, 1fr); gap: 20px;">'
|
| 178 |
+
for img_path, model_name in all_results:
|
| 179 |
+
html += f'''
|
| 180 |
+
<div style="border: 1px solid #ddd; padding: 10px; border-radius: 8px;">
|
| 181 |
+
<img src="file={img_path}" style="width: 100%; height: auto; border-radius: 4px;">
|
| 182 |
+
<p style="text-align: center; margin-top: 8px; font-weight: bold;">{model_name}</p>
|
| 183 |
+
</div>
|
| 184 |
+
'''
|
| 185 |
+
html += '</div>'
|
| 186 |
+
|
| 187 |
+
return html
|
| 188 |
|
| 189 |
except Exception as e:
|
| 190 |
print(f"An error occurred: {traceback.format_exc()}")
|
|
|
|
| 231 |
|
| 232 |
download_output = gr.File(label="Download Full-Quality Upscaled Image (Lossless PNG)")
|
| 233 |
|
| 234 |
+
# --- All models output ---
|
| 235 |
+
all_models_output = gr.HTML(label="All Models Results", visible=True)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 236 |
|
| 237 |
# --- Event Handling ---
|
| 238 |
run_button.click(
|
|
|
|
| 249 |
run_all_button.click(
|
| 250 |
fn=upscale_with_all_models,
|
| 251 |
inputs=[input_image],
|
| 252 |
+
outputs=[all_models_output],
|
|
|
|
|
|
|
|
|
|
|
|
|
| 253 |
)
|
| 254 |
|
| 255 |
# --- Pre-load the default model for a faster first-time user experience ---
|