Spaces:
Running
on
T4
Running
on
T4
yizhangliu
commited on
Commit
•
a895da4
1
Parent(s):
7e7a803
update app.py
Browse files- app.py +60 -57
- requirements.txt +1 -1
app.py
CHANGED
@@ -4,7 +4,7 @@ warnings.filterwarnings('ignore')
|
|
4 |
|
5 |
import subprocess, io, os, sys, time
|
6 |
|
7 |
-
os.system("pip install gradio==4.42.0")
|
8 |
|
9 |
import gradio as gr
|
10 |
from loguru import logger
|
@@ -607,65 +607,68 @@ def processs_inpainting(inpaint_prompt, input_image, mask_image, image_input_com
|
|
607 |
# logger.info(f'processs_inpainting_input_image={inpaint_prompt} // {input_image}')
|
608 |
# logger.info(f'processs_inpainting_mask_image={mask_image}')
|
609 |
|
610 |
-
job_image = {}
|
611 |
-
job_mask_image = None
|
612 |
-
if 'background' in input_image.keys():
|
613 |
-
|
614 |
-
|
615 |
-
|
616 |
-
|
617 |
-
|
618 |
-
|
619 |
-
|
620 |
-
|
621 |
-
|
622 |
-
|
623 |
-
|
624 |
-
logger.info(f"resize____{width}, {height}==>{resize_width}, {resize_height}")
|
625 |
-
_, temp_file_path = tempfile.mkstemp(suffix='.png')
|
626 |
-
img = input_image['background'].convert("RGB").resize((resize_width, resize_height))
|
627 |
-
img.save(temp_file_path)
|
628 |
-
# logger.info(f'processs_inpainting_temp_file_background_={temp_file_path}')
|
629 |
-
job_image["background"] = handle_file(temp_file_path)
|
630 |
-
|
631 |
-
if mask_image is not None:
|
632 |
-
_, temp_file_path = tempfile.mkstemp(suffix='.png')
|
633 |
-
img = mask_image.convert("RGB").resize((resize_width, resize_height))
|
634 |
-
# RGB(0,0,0) --> RGB(230,230,230)
|
635 |
-
img = change_RGB_value(img, 0, 0, 0, 230, 230, 230)
|
636 |
-
# RGB(255,255,255) --> RGB(170,170,170)
|
637 |
-
img = change_RGB_value(img, 255, 255, 255, 170, 170, 170)
|
638 |
-
img.save(temp_file_path)
|
639 |
-
# logger.info(f'processs_inpainting_temp_file___mask_={temp_file_path}')
|
640 |
-
job_image["layers"] = [handle_file(temp_file_path)]
|
641 |
-
|
642 |
-
if image_input_composite:
|
643 |
-
_, temp_file_path = tempfile.mkstemp(suffix='.png')
|
644 |
-
image_input_composite.save(temp_file_path)
|
645 |
-
job_image["composite"] = handle_file(temp_file_path)
|
646 |
|
647 |
-
logger.info(f
|
648 |
-
|
649 |
-
|
650 |
-
|
651 |
-
|
652 |
-
|
653 |
-
|
654 |
-
|
655 |
-
|
656 |
-
|
657 |
-
|
658 |
-
|
659 |
-
|
660 |
-
|
661 |
-
|
662 |
-
|
663 |
-
|
664 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
665 |
logger.info(f'processs_inpainting_HF = ameerazam08/FLUX.1-dev-Inpainting-Model-Beta-GPU')
|
666 |
client = Client("ameerazam08/FLUX.1-dev-Inpainting-Model-Beta-GPU")
|
667 |
job = client.submit(
|
668 |
-
input_image_editor=
|
669 |
# input_image_editor={"background":handle_file('https://ameerazam08-flux-1-dev-inpainting-model-beta-gpu.hf.space/file=/tmp/gradio/d9270300d40346834ccf596c97d9795fef6af692/background.png'),"layers":[handle_file('https://ameerazam08-flux-1-dev-inpainting-model-beta-gpu.hf.space/file=/tmp/gradio/4245eafd2d9aa8969d94dc22ffff62be95d4df02/layer_0.png')],"composite":handle_file('https://ameerazam08-flux-1-dev-inpainting-model-beta-gpu.hf.space/file=/tmp/gradio/7fe6ddfacbb3b394d19a32b01113a0460e2279ac/composite.png')},
|
670 |
prompt=inpaint_prompt,
|
671 |
negative_prompt="",
|
@@ -1031,7 +1034,7 @@ def main_gradio(args):
|
|
1031 |
if kosmos_enable:
|
1032 |
task_types.append("Kosmos-2")
|
1033 |
|
1034 |
-
brush_color = "#
|
1035 |
color_mode = "fixed"
|
1036 |
input_image = gr.ImageEditor(sources=["upload", "webcam"],
|
1037 |
image_mode='RGB',
|
|
|
4 |
|
5 |
import subprocess, io, os, sys, time
|
6 |
|
7 |
+
# os.system("pip install gradio==4.42.0")
|
8 |
|
9 |
import gradio as gr
|
10 |
from loguru import logger
|
|
|
607 |
# logger.info(f'processs_inpainting_input_image={inpaint_prompt} // {input_image}')
|
608 |
# logger.info(f'processs_inpainting_mask_image={mask_image}')
|
609 |
|
610 |
+
# job_image = {}
|
611 |
+
# job_mask_image = None
|
612 |
+
# if 'background' in input_image.keys():
|
613 |
+
# width, height = input_image['background'].size
|
614 |
+
# if max(width, height) > MAX_IMAGE_SIZE:
|
615 |
+
# if width > height:
|
616 |
+
# resize_width = MAX_IMAGE_SIZE
|
617 |
+
# resize_height = int(height * MAX_IMAGE_SIZE / width)
|
618 |
+
# else:
|
619 |
+
# resize_height = MAX_IMAGE_SIZE
|
620 |
+
# resize_width = int(width * MAX_IMAGE_SIZE / height)
|
621 |
+
# else:
|
622 |
+
# resize_width, resize_height = width, height
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
623 |
|
624 |
+
# logger.info(f"resize____{width}, {height}==>{resize_width}, {resize_height}")
|
625 |
+
# _, temp_file_path = tempfile.mkstemp(suffix='.png')
|
626 |
+
# img = input_image['background'].convert("RGB").resize((resize_width, resize_height))
|
627 |
+
# img.save(temp_file_path)
|
628 |
+
# # logger.info(f'processs_inpainting_temp_file_background_={temp_file_path}')
|
629 |
+
# job_image["background"] = handle_file(temp_file_path)
|
630 |
+
|
631 |
+
# if mask_image is not None:
|
632 |
+
# _, temp_file_path = tempfile.mkstemp(suffix='.png')
|
633 |
+
# logger.info(f"mask_temp_file_path={temp_file_path}")
|
634 |
+
# img = mask_image.convert("RGB").resize((resize_width, resize_height))
|
635 |
+
# # RGB(0,0,0) --> RGB(230,230,230)
|
636 |
+
# img = change_RGB_value(img, 0, 0, 0, 230, 230, 230)
|
637 |
+
# # RGB(255,255,255) --> RGB(170,170,170)
|
638 |
+
# # img = change_RGB_value(img, 255, 255, 255, 170, 170, 170)
|
639 |
+
# img.save(temp_file_path)
|
640 |
+
# # logger.info(f'processs_inpainting_temp_file___mask_={temp_file_path}')
|
641 |
+
# job_image["layers"] = [handle_file(temp_file_path)]
|
642 |
+
|
643 |
+
# if image_input_composite:
|
644 |
+
# _, temp_file_path = tempfile.mkstemp(suffix='.png')
|
645 |
+
# image_input_composite.save(temp_file_path)
|
646 |
+
# job_image["composite"] = handle_file(temp_file_path)
|
647 |
+
|
648 |
+
# logger.info(f'processs_inpainting_input_image={job_image}')
|
649 |
+
# logger.info(f'processs_inpainting_job_image={job_image}')
|
650 |
+
# logger.info(f'processs_inpainting_job_mask_image={job_mask_image}')
|
651 |
+
|
652 |
+
# if 0==1:
|
653 |
+
# logger.info(f'processs_inpainting_HF = Kwai-Kolors/Kolors-Inpainting')
|
654 |
+
# client = Client("Kwai-Kolors/Kolors-Inpainting", hf_token=huggingface_token, verbose=True)
|
655 |
+
# job = client.submit(
|
656 |
+
# prompt=inpaint_prompt,
|
657 |
+
# image=job_image,
|
658 |
+
# mask_image=job_mask_image,
|
659 |
+
# negative_prompt="broken fingers, deformed fingers, deformed hands, stumps, blurriness, low quality",
|
660 |
+
# seed=0,
|
661 |
+
# randomize_seed=True,
|
662 |
+
# guidance_scale=6.0,
|
663 |
+
# num_inference_steps=25,
|
664 |
+
# api_name="/infer"
|
665 |
+
# )
|
666 |
+
|
667 |
+
if 0==0:
|
668 |
logger.info(f'processs_inpainting_HF = ameerazam08/FLUX.1-dev-Inpainting-Model-Beta-GPU')
|
669 |
client = Client("ameerazam08/FLUX.1-dev-Inpainting-Model-Beta-GPU")
|
670 |
job = client.submit(
|
671 |
+
input_image_editor=input_image,
|
672 |
# input_image_editor={"background":handle_file('https://ameerazam08-flux-1-dev-inpainting-model-beta-gpu.hf.space/file=/tmp/gradio/d9270300d40346834ccf596c97d9795fef6af692/background.png'),"layers":[handle_file('https://ameerazam08-flux-1-dev-inpainting-model-beta-gpu.hf.space/file=/tmp/gradio/4245eafd2d9aa8969d94dc22ffff62be95d4df02/layer_0.png')],"composite":handle_file('https://ameerazam08-flux-1-dev-inpainting-model-beta-gpu.hf.space/file=/tmp/gradio/7fe6ddfacbb3b394d19a32b01113a0460e2279ac/composite.png')},
|
673 |
prompt=inpaint_prompt,
|
674 |
negative_prompt="",
|
|
|
1034 |
if kosmos_enable:
|
1035 |
task_types.append("Kosmos-2")
|
1036 |
|
1037 |
+
brush_color = "#FFFFFF"
|
1038 |
color_mode = "fixed"
|
1039 |
input_image = gr.ImageEditor(sources=["upload", "webcam"],
|
1040 |
image_mode='RGB',
|
requirements.txt
CHANGED
@@ -1,7 +1,7 @@
|
|
1 |
accelerate
|
2 |
addict
|
3 |
diffusers
|
4 |
-
|
5 |
huggingface_hub
|
6 |
matplotlib
|
7 |
|
|
|
1 |
accelerate
|
2 |
addict
|
3 |
diffusers
|
4 |
+
gradio==4.42.0
|
5 |
huggingface_hub
|
6 |
matplotlib
|
7 |
|