Spaces:
Running
on
Zero
Running
on
Zero
Commit
·
ac6986a
1
Parent(s):
1435d11
Revert to FAL
Browse files
app.py
CHANGED
@@ -476,59 +476,56 @@ def encode_image(image):
|
|
476 |
|
477 |
def generate_ai_bg(input_img, prompt):
|
478 |
# input_img = resize_image(input_img, 0.01)
|
479 |
-
|
480 |
-
|
481 |
-
|
482 |
-
|
483 |
-
|
484 |
-
|
485 |
-
|
486 |
-
|
487 |
-
|
488 |
-
|
489 |
|
490 |
-
|
491 |
|
492 |
-
|
493 |
|
494 |
-
|
495 |
|
496 |
-
|
497 |
|
498 |
-
|
499 |
|
500 |
-
|
501 |
|
502 |
-
from gradio_client import Client, handle_file
|
503 |
|
504 |
-
client = Client("lllyasviel/iclight-v2-vary")
|
505 |
|
506 |
-
result = client.predict(
|
507 |
-
|
508 |
-
|
509 |
-
|
510 |
-
|
511 |
-
|
512 |
-
|
513 |
-
|
514 |
-
|
515 |
-
|
516 |
-
|
517 |
-
|
518 |
-
|
519 |
-
|
520 |
-
|
521 |
-
|
522 |
-
|
523 |
-
)
|
524 |
-
print(result)
|
525 |
-
|
526 |
-
relight_img_path = result[0][0]['image']
|
527 |
|
528 |
-
#
|
529 |
-
relight_img = Image.open(relight_img_path).convert("RGBA")
|
530 |
|
531 |
-
# relight_img = Image.open(
|
532 |
|
533 |
return relight_img
|
534 |
|
@@ -593,13 +590,13 @@ def blend_details(input_image, relit_image, masked_image, scaling_factor=1):
|
|
593 |
@spaces.GPU
|
594 |
def generate_image(input_image_path, prompt):
|
595 |
|
596 |
-
resized_input_img = resize_to_square(input_image_path,
|
597 |
|
598 |
resized_input_img_path = '/tmp/gradio/resized_input_img.png'
|
599 |
|
600 |
resized_input_img.convert("RGBA").save(resized_input_img_path, "PNG")
|
601 |
|
602 |
-
ai_gen_image = generate_ai_bg(
|
603 |
|
604 |
# mask_input_image = run_grounded_sam(resized_input_img)
|
605 |
|
|
|
476 |
|
477 |
def generate_ai_bg(input_img, prompt):
|
478 |
# input_img = resize_image(input_img, 0.01)
|
479 |
+
hf_input_img = encode_image(input_img)
|
480 |
+
|
481 |
+
handler = fal_client.submit(
|
482 |
+
"fal-ai/iclight-v2",
|
483 |
+
arguments={
|
484 |
+
"prompt": prompt,
|
485 |
+
"image_url": hf_input_img
|
486 |
+
},
|
487 |
+
webhook_url="https://optional.webhook.url/for/results",
|
488 |
+
)
|
489 |
|
490 |
+
request_id = handler.request_id
|
491 |
|
492 |
+
status = fal_client.status("fal-ai/iclight-v2", request_id, with_logs=True)
|
493 |
|
494 |
+
result = fal_client.result("fal-ai/iclight-v2", request_id)
|
495 |
|
496 |
+
relight_img_path = result['images'][0]['url']
|
497 |
|
498 |
+
response = requests.get(relight_img_path, stream=True)
|
499 |
|
500 |
+
relight_img = Image.open(BytesIO(response.content)).convert("RGBA")
|
501 |
|
502 |
+
# from gradio_client import Client, handle_file
|
503 |
|
504 |
+
# client = Client("lllyasviel/iclight-v2-vary")
|
505 |
|
506 |
+
# result = client.predict(
|
507 |
+
# input_fg=handle_file(input_img),
|
508 |
+
# bg_source="None",
|
509 |
+
# prompt=prompt,
|
510 |
+
# image_width=256,
|
511 |
+
# image_height=256,
|
512 |
+
# num_samples=1,
|
513 |
+
# seed=12345,
|
514 |
+
# steps=25,
|
515 |
+
# n_prompt="lowres, bad anatomy, bad hands, cropped, worst quality",
|
516 |
+
# cfg=2,
|
517 |
+
# gs=5,
|
518 |
+
# enable_hr_fix=True,
|
519 |
+
# hr_downscale=0.5,
|
520 |
+
# lowres_denoise=0.8,
|
521 |
+
# highres_denoise=0.99,
|
522 |
+
# api_name="/process"
|
523 |
+
# )
|
524 |
+
# print(result)
|
|
|
|
|
525 |
|
526 |
+
# relight_img_path = result[0][0]['image']
|
|
|
527 |
|
528 |
+
# relight_img = Image.open(relight_img_path).convert("RGBA")
|
529 |
|
530 |
return relight_img
|
531 |
|
|
|
590 |
@spaces.GPU
|
591 |
def generate_image(input_image_path, prompt):
|
592 |
|
593 |
+
resized_input_img = resize_to_square(input_image_path, 256)
|
594 |
|
595 |
resized_input_img_path = '/tmp/gradio/resized_input_img.png'
|
596 |
|
597 |
resized_input_img.convert("RGBA").save(resized_input_img_path, "PNG")
|
598 |
|
599 |
+
ai_gen_image = generate_ai_bg(resized_input_img, prompt)
|
600 |
|
601 |
# mask_input_image = run_grounded_sam(resized_input_img)
|
602 |
|