Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -221,7 +221,6 @@ def enhance_image(
|
|
| 221 |
randomize_seed,
|
| 222 |
num_inference_steps,
|
| 223 |
upscale_factor,
|
| 224 |
-
guidance_scale,
|
| 225 |
denoising_strength,
|
| 226 |
use_generated_caption,
|
| 227 |
custom_prompt,
|
|
@@ -272,7 +271,7 @@ def enhance_image(
|
|
| 272 |
control_image,
|
| 273 |
denoising_strength,
|
| 274 |
num_inference_steps,
|
| 275 |
-
guidance_scale
|
| 276 |
generator,
|
| 277 |
tile_size=1024,
|
| 278 |
overlap=32
|
|
@@ -286,11 +285,11 @@ def enhance_image(
|
|
| 286 |
|
| 287 |
|
| 288 |
# Create Gradio interface
|
| 289 |
-
with gr.Blocks(css=css, title="π¨ AI Image
|
| 290 |
gr.HTML("""
|
| 291 |
<div class="main-header">
|
| 292 |
-
<h1>π¨ AI Image
|
| 293 |
-
<p>Upload an image or provide a URL to
|
| 294 |
<p>Currently running on <strong>{}</strong></p>
|
| 295 |
</div>
|
| 296 |
""".format(power_device))
|
|
@@ -304,7 +303,7 @@ with gr.Blocks(css=css, title="π¨ AI Image Enhancer - Florence-2 + FLUX") as d
|
|
| 304 |
input_image = gr.Image(
|
| 305 |
label="Upload Image",
|
| 306 |
type="pil",
|
| 307 |
-
height=
|
| 308 |
)
|
| 309 |
|
| 310 |
with gr.TabItem("π Image URL"):
|
|
@@ -328,7 +327,7 @@ with gr.Blocks(css=css, title="π¨ AI Image Enhancer - Florence-2 + FLUX") as d
|
|
| 328 |
lines=2
|
| 329 |
)
|
| 330 |
|
| 331 |
-
gr.HTML("<h3>βοΈ
|
| 332 |
|
| 333 |
upscale_factor = gr.Slider(
|
| 334 |
label="Upscale Factor",
|
|
@@ -348,15 +347,6 @@ with gr.Blocks(css=css, title="π¨ AI Image Enhancer - Florence-2 + FLUX") as d
|
|
| 348 |
info="More steps = better quality but slower"
|
| 349 |
)
|
| 350 |
|
| 351 |
-
guidance_scale = gr.Slider(
|
| 352 |
-
label="Guidance Scale",
|
| 353 |
-
minimum=1.0,
|
| 354 |
-
maximum=10.0,
|
| 355 |
-
step=0.5,
|
| 356 |
-
value=3.5,
|
| 357 |
-
info="How closely to follow the prompt"
|
| 358 |
-
)
|
| 359 |
-
|
| 360 |
denoising_strength = gr.Slider(
|
| 361 |
label="Denoising Strength",
|
| 362 |
minimum=0.0,
|
|
@@ -381,19 +371,20 @@ with gr.Blocks(css=css, title="π¨ AI Image Enhancer - Florence-2 + FLUX") as d
|
|
| 381 |
)
|
| 382 |
|
| 383 |
enhance_btn = gr.Button(
|
| 384 |
-
"π
|
| 385 |
variant="primary",
|
| 386 |
size="lg"
|
| 387 |
)
|
| 388 |
|
| 389 |
-
with gr.Column(scale=
|
| 390 |
gr.HTML("<h3>π Results</h3>")
|
| 391 |
|
| 392 |
result_slider = ImageSlider(
|
| 393 |
-
label="Input /
|
| 394 |
type="pil",
|
| 395 |
interactive=True,
|
| 396 |
-
height=
|
|
|
|
| 397 |
)
|
| 398 |
|
| 399 |
with gr.Row():
|
|
@@ -410,26 +401,6 @@ with gr.Blocks(css=css, title="π¨ AI Image Enhancer - Florence-2 + FLUX") as d
|
|
| 410 |
interactive=False
|
| 411 |
)
|
| 412 |
|
| 413 |
-
# Examples
|
| 414 |
-
gr.Examples(
|
| 415 |
-
examples=[
|
| 416 |
-
[None, "https://upload.wikimedia.org/wikipedia/commons/thumb/a/a7/Example.jpg/800px-Example.jpg", 42, False, 25, 2, 3.5, 0.3, True, ""],
|
| 417 |
-
[None, "https://picsum.photos/512/512", 123, False, 25, 3, 4.0, 0.3, True, ""],
|
| 418 |
-
],
|
| 419 |
-
inputs=[
|
| 420 |
-
input_image,
|
| 421 |
-
image_url,
|
| 422 |
-
seed,
|
| 423 |
-
randomize_seed,
|
| 424 |
-
num_inference_steps,
|
| 425 |
-
upscale_factor,
|
| 426 |
-
guidance_scale,
|
| 427 |
-
denoising_strength,
|
| 428 |
-
use_generated_caption,
|
| 429 |
-
custom_prompt,
|
| 430 |
-
]
|
| 431 |
-
)
|
| 432 |
-
|
| 433 |
# Event handler
|
| 434 |
enhance_btn.click(
|
| 435 |
fn=enhance_image,
|
|
@@ -440,7 +411,6 @@ with gr.Blocks(css=css, title="π¨ AI Image Enhancer - Florence-2 + FLUX") as d
|
|
| 440 |
randomize_seed,
|
| 441 |
num_inference_steps,
|
| 442 |
upscale_factor,
|
| 443 |
-
guidance_scale,
|
| 444 |
denoising_strength,
|
| 445 |
use_generated_caption,
|
| 446 |
custom_prompt,
|
|
@@ -454,11 +424,26 @@ with gr.Blocks(css=css, title="π¨ AI Image Enhancer - Florence-2 + FLUX") as d
|
|
| 454 |
<ol>
|
| 455 |
<li><strong>Florence-2</strong> analyzes your image and generates a detailed caption</li>
|
| 456 |
<li>Initial upscale with LANCZOS interpolation (or ESRGAN if installed)</li>
|
| 457 |
-
<li><strong>FLUX Img2Img</strong>
|
| 458 |
</ol>
|
| 459 |
<p><strong>Note:</strong> Output limited to 8192x8192 pixels total budget. Tiling enables larger sizes.</p>
|
| 460 |
</div>
|
| 461 |
""")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 462 |
|
| 463 |
if __name__ == "__main__":
|
| 464 |
demo.queue().launch(share=True, server_name="0.0.0.0", server_port=7860)
|
|
|
|
| 221 |
randomize_seed,
|
| 222 |
num_inference_steps,
|
| 223 |
upscale_factor,
|
|
|
|
| 224 |
denoising_strength,
|
| 225 |
use_generated_caption,
|
| 226 |
custom_prompt,
|
|
|
|
| 271 |
control_image,
|
| 272 |
denoising_strength,
|
| 273 |
num_inference_steps,
|
| 274 |
+
1.0, # Hardcoded guidance_scale to 1
|
| 275 |
generator,
|
| 276 |
tile_size=1024,
|
| 277 |
overlap=32
|
|
|
|
| 285 |
|
| 286 |
|
| 287 |
# Create Gradio interface
|
| 288 |
+
with gr.Blocks(css=css, title="π¨ AI Image Upscaler - Florence-2 + FLUX") as demo:
|
| 289 |
gr.HTML("""
|
| 290 |
<div class="main-header">
|
| 291 |
+
<h1>π¨ AI Image Upscaler</h1>
|
| 292 |
+
<p>Upload an image or provide a URL to upscale it using Florence-2 captioning and FLUX upscaling</p>
|
| 293 |
<p>Currently running on <strong>{}</strong></p>
|
| 294 |
</div>
|
| 295 |
""".format(power_device))
|
|
|
|
| 303 |
input_image = gr.Image(
|
| 304 |
label="Upload Image",
|
| 305 |
type="pil",
|
| 306 |
+
height=200 # Made smaller
|
| 307 |
)
|
| 308 |
|
| 309 |
with gr.TabItem("π Image URL"):
|
|
|
|
| 327 |
lines=2
|
| 328 |
)
|
| 329 |
|
| 330 |
+
gr.HTML("<h3>βοΈ Upscaling Settings</h3>")
|
| 331 |
|
| 332 |
upscale_factor = gr.Slider(
|
| 333 |
label="Upscale Factor",
|
|
|
|
| 347 |
info="More steps = better quality but slower"
|
| 348 |
)
|
| 349 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 350 |
denoising_strength = gr.Slider(
|
| 351 |
label="Denoising Strength",
|
| 352 |
minimum=0.0,
|
|
|
|
| 371 |
)
|
| 372 |
|
| 373 |
enhance_btn = gr.Button(
|
| 374 |
+
"π Upscale Image",
|
| 375 |
variant="primary",
|
| 376 |
size="lg"
|
| 377 |
)
|
| 378 |
|
| 379 |
+
with gr.Column(scale=2): # Larger scale for results
|
| 380 |
gr.HTML("<h3>π Results</h3>")
|
| 381 |
|
| 382 |
result_slider = ImageSlider(
|
| 383 |
+
label="Input / Upscaled",
|
| 384 |
type="pil",
|
| 385 |
interactive=True,
|
| 386 |
+
height=600, # Made larger
|
| 387 |
+
elem_id="result_slider"
|
| 388 |
)
|
| 389 |
|
| 390 |
with gr.Row():
|
|
|
|
| 401 |
interactive=False
|
| 402 |
)
|
| 403 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 404 |
# Event handler
|
| 405 |
enhance_btn.click(
|
| 406 |
fn=enhance_image,
|
|
|
|
| 411 |
randomize_seed,
|
| 412 |
num_inference_steps,
|
| 413 |
upscale_factor,
|
|
|
|
| 414 |
denoising_strength,
|
| 415 |
use_generated_caption,
|
| 416 |
custom_prompt,
|
|
|
|
| 424 |
<ol>
|
| 425 |
<li><strong>Florence-2</strong> analyzes your image and generates a detailed caption</li>
|
| 426 |
<li>Initial upscale with LANCZOS interpolation (or ESRGAN if installed)</li>
|
| 427 |
+
<li><strong>FLUX Img2Img</strong> upscales the upscaled image with tiled AI diffusion guided by the caption</li>
|
| 428 |
</ol>
|
| 429 |
<p><strong>Note:</strong> Output limited to 8192x8192 pixels total budget. Tiling enables larger sizes.</p>
|
| 430 |
</div>
|
| 431 |
""")
|
| 432 |
+
|
| 433 |
+
# Custom CSS for slider
|
| 434 |
+
gr.HTML("""
|
| 435 |
+
<style>
|
| 436 |
+
#result_slider .slider {
|
| 437 |
+
width: 100% !important;
|
| 438 |
+
max-width: inherit !important;
|
| 439 |
+
}
|
| 440 |
+
#result_slider img {
|
| 441 |
+
object-fit: contain !important;
|
| 442 |
+
width: 100% !important;
|
| 443 |
+
height: auto !important;
|
| 444 |
+
}
|
| 445 |
+
</style>
|
| 446 |
+
""")
|
| 447 |
|
| 448 |
if __name__ == "__main__":
|
| 449 |
demo.queue().launch(share=True, server_name="0.0.0.0", server_port=7860)
|