Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -356,7 +356,7 @@ class BGSource(Enum):
|
|
| 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,17 +381,39 @@ def create_demo():
|
|
| 381 |
padding: 6px !important;
|
| 382 |
}
|
| 383 |
</style>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 384 |
""")
|
| 385 |
|
| 386 |
with gr.Column():
|
| 387 |
input_fg = gr.Image(sources='upload', type="numpy", label="Imazhi i Ngarkuar", height=480)
|
| 388 |
prompt = gr.Textbox(label="Përshkrimi", placeholder="Shkruani përshkrimin këtu")
|
| 389 |
bg_source = gr.Radio(choices=[e.value for e in BGSource], value=BGSource.NONE.value, label="Preferenca e Ndriçimit", type='value')
|
|
|
|
| 390 |
relight_button = gr.Button(value="Rindriço")
|
| 391 |
-
result_gallery = gr.Gallery(label="Rezultatet", height=832, object_fit='contain')
|
| 392 |
# Hidden components for other parameters and output_bg
|
| 393 |
-
image_width = gr.Slider(label="Gjerësia e Imazhit", minimum=256, maximum=1024, value=640, step=64, visible=False)
|
| 394 |
-
image_height = gr.Slider(label="Lartësia e Imazhit", minimum=256, maximum=1024, value=640, step=64, visible=False)
|
| 395 |
num_samples = gr.Slider(label="Numri i Imazheve", minimum=1, maximum=12, value=1, step=1, visible=False)
|
| 396 |
seed = gr.Number(label="Fara", value=12345, precision=0, visible=False)
|
| 397 |
steps = gr.Slider(label="Hapat", minimum=1, maximum=100, value=50, step=1, visible=False)
|
|
@@ -403,6 +425,14 @@ def create_demo():
|
|
| 403 |
lowres_denoise = gr.Slider(label="Denoise i Rezolutës së Ulët", minimum=0.1, maximum=1.0, value=0.9, step=0.01, visible=False)
|
| 404 |
output_bg = gr.Image(type="numpy", label="Parapërpunimi i Planit të Parë", visible=False)
|
| 405 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 406 |
# Bind the relight button
|
| 407 |
ips = [
|
| 408 |
input_fg, prompt, image_width, image_height, num_samples, seed, steps,
|
|
|
|
| 356 |
# UI Layout
|
| 357 |
def create_demo():
|
| 358 |
with gr.Blocks() as block:
|
| 359 |
+
# CSS for 320px gap, download button scaling, and JavaScript for aspect ratio
|
| 360 |
gr.HTML("""
|
| 361 |
<style>
|
| 362 |
body::before {
|
|
|
|
| 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():
|
| 408 |
input_fg = gr.Image(sources='upload', type="numpy", label="Imazhi i Ngarkuar", height=480)
|
| 409 |
prompt = gr.Textbox(label="Përshkrimi", placeholder="Shkruani përshkrimin këtu")
|
| 410 |
bg_source = gr.Radio(choices=[e.value for e in BGSource], value=BGSource.NONE.value, label="Preferenca e Ndriçimit", type='value')
|
| 411 |
+
aspect_ratio = gr.Radio(choices=["9:16", "1:1", "16:9"], value="1:1", label="Raporti i Aspektit")
|
| 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, elem_id="image_width_slider")
|
| 416 |
+
image_height = gr.Slider(label="Lartësia e Imazhit", minimum=256, maximum=1024, value=640, step=64, visible=False, elem_id="image_height_slider")
|
| 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)
|
|
|
|
| 425 |
lowres_denoise = gr.Slider(label="Denoise i Rezolutës së Ulët", minimum=0.1, maximum=1.0, value=0.9, step=0.01, visible=False)
|
| 426 |
output_bg = gr.Image(type="numpy", label="Parapërpunimi i Planit të Parë", visible=False)
|
| 427 |
|
| 428 |
+
# Update hidden sliders based on aspect ratio
|
| 429 |
+
aspect_ratio.change(
|
| 430 |
+
fn=lambda ratio: None,
|
| 431 |
+
inputs=[aspect_ratio],
|
| 432 |
+
outputs=None,
|
| 433 |
+
_js="function(ratio) { updateAspectRatio(ratio, 'image_width_slider', 'image_height_slider'); }"
|
| 434 |
+
)
|
| 435 |
+
|
| 436 |
# Bind the relight button
|
| 437 |
ips = [
|
| 438 |
input_fg, prompt, image_width, image_height, num_samples, seed, steps,
|