Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -227,14 +227,14 @@ def translate_albanian_to_english(text):
|
|
| 227 |
@torch.inference_mode()
|
| 228 |
def process(input_fg, prompt_albanian, image_width, image_height, num_samples, seed, steps, a_prompt, n_prompt, cfg, highres_scale, highres_denoise, lowres_denoise, bg_source):
|
| 229 |
if not input_fg.any():
|
| 230 |
-
return None, None
|
| 231 |
|
| 232 |
if not prompt_albanian.strip():
|
| 233 |
prompt = ""
|
| 234 |
else:
|
| 235 |
prompt = translate_albanian_to_english(prompt_albanian)
|
| 236 |
if prompt.startswith("Përkthimi dështoi"):
|
| 237 |
-
return None, None
|
| 238 |
|
| 239 |
bg_source = BGSource(bg_source)
|
| 240 |
input_bg = None
|
|
@@ -336,17 +336,26 @@ def process(input_fg, prompt_albanian, image_width, image_height, num_samples, s
|
|
| 336 |
|
| 337 |
pixels = vae.decode(latents).sample
|
| 338 |
|
| 339 |
-
return pytorch2numpy(pixels)
|
| 340 |
|
| 341 |
@spaces.GPU
|
| 342 |
@torch.inference_mode()
|
| 343 |
def process_relight(input_fg, prompt_albanian, image_width, image_height, num_samples, seed, steps, a_prompt, n_prompt, cfg, highres_scale, highres_denoise, lowres_denoise, bg_source):
|
| 344 |
if not input_fg.any():
|
| 345 |
-
return None, None
|
| 346 |
|
| 347 |
input_fg, matting = run_rmbg(input_fg)
|
| 348 |
-
results
|
| 349 |
-
return input_fg, results
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 350 |
|
| 351 |
class BGSource(Enum):
|
| 352 |
NONE = "Asnjë"
|
|
@@ -355,7 +364,31 @@ class BGSource(Enum):
|
|
| 355 |
TOP = "Dritë nga Sipër"
|
| 356 |
BOTTOM = "Dritë nga Poshtë"
|
| 357 |
|
| 358 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 359 |
with block:
|
| 360 |
with gr.Row():
|
| 361 |
with gr.Column():
|
|
@@ -366,16 +399,15 @@ with block:
|
|
| 366 |
bg_source = gr.Radio(choices=[e.value for e in BGSource],
|
| 367 |
value=BGSource.NONE.value,
|
| 368 |
label="Preferenca e Ndriçimit (Latenti Fillestar)", type='value')
|
|
|
|
| 369 |
relight_button = gr.Button(value="Gjenero")
|
| 370 |
|
| 371 |
with gr.Group():
|
| 372 |
with gr.Row():
|
| 373 |
num_samples = gr.Slider(label="Numri i Imazheve", minimum=1, maximum=12, value=1, step=1, visible=False)
|
| 374 |
seed = gr.Number(label="Farë", value=-1, precision=0, visible=False)
|
| 375 |
-
|
| 376 |
-
|
| 377 |
-
image_width = gr.Slider(label="Gjerësia e Imazhit", minimum=256, maximum=1024, value=512, step=64)
|
| 378 |
-
image_height = gr.Slider(label="Lartësia e Imazhit", minimum=256, maximum=1024, value=640, step=64)
|
| 379 |
|
| 380 |
with gr.Accordion("Opsionet e Avancuara", open=False, visible=False):
|
| 381 |
steps = gr.Slider(label="Hapat", minimum=1, maximum=100, value=50, step=1)
|
|
@@ -387,10 +419,15 @@ with block:
|
|
| 387 |
n_prompt = gr.Textbox(label="Negative Prompt", value='lowres, bad anatomy, bad hands, cropped, worst quality')
|
| 388 |
with gr.Column():
|
| 389 |
result_gallery = gr.Gallery(height=832, object_fit='contain', label='Rezultatet')
|
| 390 |
-
status = gr.Textbox(label="Statusi", interactive=False)
|
| 391 |
with gr.Row():
|
| 392 |
dummy_image_for_outputs = gr.Image(visible=False, label='Rezultati')
|
| 393 |
ips = [input_fg, prompt_albanian, image_width, image_height, num_samples, seed, steps, a_prompt, n_prompt, cfg, highres_scale, highres_denoise, lowres_denoise, bg_source]
|
| 394 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 395 |
|
| 396 |
block.launch(server_name='0.0.0.0')
|
|
|
|
| 227 |
@torch.inference_mode()
|
| 228 |
def process(input_fg, prompt_albanian, image_width, image_height, num_samples, seed, steps, a_prompt, n_prompt, cfg, highres_scale, highres_denoise, lowres_denoise, bg_source):
|
| 229 |
if not input_fg.any():
|
| 230 |
+
return None, None
|
| 231 |
|
| 232 |
if not prompt_albanian.strip():
|
| 233 |
prompt = ""
|
| 234 |
else:
|
| 235 |
prompt = translate_albanian_to_english(prompt_albanian)
|
| 236 |
if prompt.startswith("Përkthimi dështoi"):
|
| 237 |
+
return None, None
|
| 238 |
|
| 239 |
bg_source = BGSource(bg_source)
|
| 240 |
input_bg = None
|
|
|
|
| 336 |
|
| 337 |
pixels = vae.decode(latents).sample
|
| 338 |
|
| 339 |
+
return pytorch2numpy(pixels)
|
| 340 |
|
| 341 |
@spaces.GPU
|
| 342 |
@torch.inference_mode()
|
| 343 |
def process_relight(input_fg, prompt_albanian, image_width, image_height, num_samples, seed, steps, a_prompt, n_prompt, cfg, highres_scale, highres_denoise, lowres_denoise, bg_source):
|
| 344 |
if not input_fg.any():
|
| 345 |
+
return None, None
|
| 346 |
|
| 347 |
input_fg, matting = run_rmbg(input_fg)
|
| 348 |
+
results = process(input_fg, prompt_albanian, image_width, image_height, num_samples, seed, steps, a_prompt, n_prompt, cfg, highres_scale, highres_denoise, lowres_denoise, bg_source)
|
| 349 |
+
return input_fg, results
|
| 350 |
+
|
| 351 |
+
def update_resolution(aspect_ratio):
|
| 352 |
+
if aspect_ratio == "9:16":
|
| 353 |
+
return 512, 910
|
| 354 |
+
elif aspect_ratio == "1:1":
|
| 355 |
+
return 640, 640
|
| 356 |
+
elif aspect_ratio == "16:9":
|
| 357 |
+
return 910, 512
|
| 358 |
+
return 512, 910 # Default to 9:16
|
| 359 |
|
| 360 |
class BGSource(Enum):
|
| 361 |
NONE = "Asnjë"
|
|
|
|
| 364 |
TOP = "Dritë nga Sipër"
|
| 365 |
BOTTOM = "Dritë nga Poshtë"
|
| 366 |
|
| 367 |
+
css = """
|
| 368 |
+
body::before {
|
| 369 |
+
content: "";
|
| 370 |
+
display: block;
|
| 371 |
+
height: 320px;
|
| 372 |
+
background-color: var(--body-background-fill);
|
| 373 |
+
}
|
| 374 |
+
button[aria-label="Fullscreen"], button[aria-label="Fullscreen"]:hover {
|
| 375 |
+
display: none !important;
|
| 376 |
+
visibility: hidden !important;
|
| 377 |
+
opacity: 0 !important;
|
| 378 |
+
pointer-events: none !important;
|
| 379 |
+
}
|
| 380 |
+
button[aria-label="Share"], button[aria-label="Share"]:hover {
|
| 381 |
+
display: none !important;
|
| 382 |
+
}
|
| 383 |
+
button[aria-label="Download"] {
|
| 384 |
+
transform: scale(3);
|
| 385 |
+
transform-origin: top right;
|
| 386 |
+
margin: 0 !important;
|
| 387 |
+
padding: 6px !important;
|
| 388 |
+
}
|
| 389 |
+
"""
|
| 390 |
+
|
| 391 |
+
block = gr.Blocks(css=css).queue()
|
| 392 |
with block:
|
| 393 |
with gr.Row():
|
| 394 |
with gr.Column():
|
|
|
|
| 399 |
bg_source = gr.Radio(choices=[e.value for e in BGSource],
|
| 400 |
value=BGSource.NONE.value,
|
| 401 |
label="Preferenca e Ndriçimit (Latenti Fillestar)", type='value')
|
| 402 |
+
aspect_ratio = gr.Radio(choices=["9:16", "1:1", "16:9"], value="9:16", label="Raporti i Imazhit")
|
| 403 |
relight_button = gr.Button(value="Gjenero")
|
| 404 |
|
| 405 |
with gr.Group():
|
| 406 |
with gr.Row():
|
| 407 |
num_samples = gr.Slider(label="Numri i Imazheve", minimum=1, maximum=12, value=1, step=1, visible=False)
|
| 408 |
seed = gr.Number(label="Farë", value=-1, precision=0, visible=False)
|
| 409 |
+
image_width = gr.State(value=512)
|
| 410 |
+
image_height = gr.State(value=910)
|
|
|
|
|
|
|
| 411 |
|
| 412 |
with gr.Accordion("Opsionet e Avancuara", open=False, visible=False):
|
| 413 |
steps = gr.Slider(label="Hapat", minimum=1, maximum=100, value=50, step=1)
|
|
|
|
| 419 |
n_prompt = gr.Textbox(label="Negative Prompt", value='lowres, bad anatomy, bad hands, cropped, worst quality')
|
| 420 |
with gr.Column():
|
| 421 |
result_gallery = gr.Gallery(height=832, object_fit='contain', label='Rezultatet')
|
|
|
|
| 422 |
with gr.Row():
|
| 423 |
dummy_image_for_outputs = gr.Image(visible=False, label='Rezultati')
|
| 424 |
ips = [input_fg, prompt_albanian, image_width, image_height, num_samples, seed, steps, a_prompt, n_prompt, cfg, highres_scale, highres_denoise, lowres_denoise, bg_source]
|
| 425 |
+
aspect_ratio.change(
|
| 426 |
+
fn=update_resolution,
|
| 427 |
+
inputs=[aspect_ratio],
|
| 428 |
+
outputs=[image_width, image_height],
|
| 429 |
+
queue=False
|
| 430 |
+
)
|
| 431 |
+
relight_button.click(fn=process_relight, inputs=ips, outputs=[output_bg, result_gallery])
|
| 432 |
|
| 433 |
block.launch(server_name='0.0.0.0')
|