Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -353,10 +353,24 @@ class BGSource(Enum):
|
|
| 353 |
TOP = "Dritë nga Sipër"
|
| 354 |
BOTTOM = "Dritë nga Poshtë"
|
| 355 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 356 |
# UI Layout
|
| 357 |
def create_demo():
|
| 358 |
with gr.Blocks() as block:
|
| 359 |
-
# CSS for 320px gap
|
| 360 |
gr.HTML("""
|
| 361 |
<style>
|
| 362 |
body::before {
|
|
@@ -381,27 +395,6 @@ def create_demo():
|
|
| 381 |
padding: 6px !important;
|
| 382 |
}
|
| 383 |
</style>
|
| 384 |
-
<script>
|
| 385 |
-
function updateAspectRatio(ratio, widthSliderId, heightSliderId) {
|
| 386 |
-
const widthSlider = document.querySelector(`#${widthSliderId} input`);
|
| 387 |
-
const heightSlider = document.querySelector(`#${heightSliderId} input`);
|
| 388 |
-
if (!widthSlider || !heightSlider) return;
|
| 389 |
-
|
| 390 |
-
if (ratio === "1:1") {
|
| 391 |
-
widthSlider.value = 640;
|
| 392 |
-
heightSlider.value = 640;
|
| 393 |
-
} else if (ratio === "9:16") {
|
| 394 |
-
widthSlider.value = 512;
|
| 395 |
-
heightSlider.value = Math.round(512 * 16 / 9);
|
| 396 |
-
} else if (ratio === "16:9") {
|
| 397 |
-
widthSlider.value = Math.round(512 * 16 / 9);
|
| 398 |
-
heightSlider.value = 512;
|
| 399 |
-
}
|
| 400 |
-
|
| 401 |
-
widthSlider.dispatchEvent(new Event('input'));
|
| 402 |
-
heightSlider.dispatchEvent(new Event('input'));
|
| 403 |
-
}
|
| 404 |
-
</script>
|
| 405 |
""")
|
| 406 |
|
| 407 |
with gr.Column():
|
|
@@ -412,8 +405,8 @@ def create_demo():
|
|
| 412 |
relight_button = gr.Button(value="Rindriço")
|
| 413 |
result_gallery = gr.Gallery(label="Rezultatet", height=832, object_fit='contain')
|
| 414 |
# Hidden components for other parameters and output_bg
|
| 415 |
-
image_width = gr.Slider(label="Gjerësia e Imazhit", minimum=256, maximum=1024, value=640, step=64, visible=False
|
| 416 |
-
image_height = gr.Slider(label="Lartësia e Imazhit", minimum=256, maximum=1024, value=640, step=64, visible=False
|
| 417 |
num_samples = gr.Slider(label="Numri i Imazheve", minimum=1, maximum=12, value=1, step=1, visible=False)
|
| 418 |
seed = gr.Number(label="Fara", value=12345, precision=0, visible=False)
|
| 419 |
steps = gr.Slider(label="Hapat", minimum=1, maximum=100, value=50, step=1, visible=False)
|
|
@@ -427,10 +420,9 @@ def create_demo():
|
|
| 427 |
|
| 428 |
# Update hidden sliders based on aspect ratio
|
| 429 |
aspect_ratio.change(
|
| 430 |
-
fn=
|
| 431 |
inputs=[aspect_ratio],
|
| 432 |
-
outputs=
|
| 433 |
-
_js="function(ratio) { updateAspectRatio(ratio, 'image_width_slider', 'image_height_slider'); }"
|
| 434 |
)
|
| 435 |
|
| 436 |
# Bind the relight button
|
|
|
|
| 353 |
TOP = "Dritë nga Sipër"
|
| 354 |
BOTTOM = "Dritë nga Poshtë"
|
| 355 |
|
| 356 |
+
# Function to update aspect ratio
|
| 357 |
+
def update_aspect_ratio(ratio):
|
| 358 |
+
if ratio == "1:1":
|
| 359 |
+
return 640, 640
|
| 360 |
+
elif ratio == "9:16":
|
| 361 |
+
width = 512
|
| 362 |
+
height = int(round(512 * 16 / 9 / 64)) * 64 # Round to nearest multiple of 64
|
| 363 |
+
return width, height
|
| 364 |
+
elif ratio == "16:9":
|
| 365 |
+
width = int(round(512 * 16 / 9 / 64)) * 64 # Round to nearest multiple of 64
|
| 366 |
+
height = 512
|
| 367 |
+
return width, height
|
| 368 |
+
return 640, 640 # Default to 1:1
|
| 369 |
+
|
| 370 |
# UI Layout
|
| 371 |
def create_demo():
|
| 372 |
with gr.Blocks() as block:
|
| 373 |
+
# CSS for 320px gap and download button scaling
|
| 374 |
gr.HTML("""
|
| 375 |
<style>
|
| 376 |
body::before {
|
|
|
|
| 395 |
padding: 6px !important;
|
| 396 |
}
|
| 397 |
</style>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 398 |
""")
|
| 399 |
|
| 400 |
with gr.Column():
|
|
|
|
| 405 |
relight_button = gr.Button(value="Rindriço")
|
| 406 |
result_gallery = gr.Gallery(label="Rezultatet", height=832, object_fit='contain')
|
| 407 |
# Hidden components for other parameters and output_bg
|
| 408 |
+
image_width = gr.Slider(label="Gjerësia e Imazhit", minimum=256, maximum=1024, value=640, step=64, visible=False)
|
| 409 |
+
image_height = gr.Slider(label="Lartësia e Imazhit", minimum=256, maximum=1024, value=640, step=64, visible=False)
|
| 410 |
num_samples = gr.Slider(label="Numri i Imazheve", minimum=1, maximum=12, value=1, step=1, visible=False)
|
| 411 |
seed = gr.Number(label="Fara", value=12345, precision=0, visible=False)
|
| 412 |
steps = gr.Slider(label="Hapat", minimum=1, maximum=100, value=50, step=1, visible=False)
|
|
|
|
| 420 |
|
| 421 |
# Update hidden sliders based on aspect ratio
|
| 422 |
aspect_ratio.change(
|
| 423 |
+
fn=update_aspect_ratio,
|
| 424 |
inputs=[aspect_ratio],
|
| 425 |
+
outputs=[image_width, image_height]
|
|
|
|
| 426 |
)
|
| 427 |
|
| 428 |
# Bind the relight button
|