|
import os |
|
import gradio as gr |
|
from gradio_client import Client, handle_file |
|
from PIL import Image |
|
|
|
def predict(imgs, garm_img): |
|
print(imgs, garm_img) |
|
client = Client("life4cut/ff-v1", hf_token=os.environ.get('HF_TOKEN_FF')) |
|
result = client.predict( |
|
|
|
|
|
dict={"background":handle_file(imgs),"layers":[],"composite":None}, |
|
garm_img=handle_file(garm_img), |
|
garment_des="Hello!!", |
|
is_checked=True, |
|
is_checked_crop=False, |
|
denoise_steps=30, |
|
seed=42, |
|
api_name="/tryon" |
|
) |
|
|
|
return result[0], result[1] |
|
|
|
|
|
|
|
|
|
|
|
example_path = os.path.join(os.path.dirname(__file__), 'example') |
|
garm_list = os.listdir(os.path.join(example_path,"cloth")) |
|
garm_list_path = [os.path.join(example_path,"cloth",garm) for garm in garm_list] |
|
human_list = os.listdir(os.path.join(example_path,"human")) |
|
human_list_path = [os.path.join(example_path,"human",human) for human in human_list] |
|
|
|
image_blocks = gr.Blocks().queue() |
|
with image_blocks as demo: |
|
gr.Markdown("## fashion filter") |
|
with gr.Row(): |
|
with gr.Column(): |
|
|
|
imgs = gr.Image(sources='upload', type="filepath", label='Human. Mask with pen or use auto-masking') |
|
with gr.Row(): |
|
is_checked = gr.Checkbox(label="Yes", info="Use auto-generated mask (Takes 5 seconds)",value=True) |
|
with gr.Row(): |
|
is_checked_crop = gr.Checkbox(label="Yes", info="Use auto-crop & resizing",value=False) |
|
example = gr.Examples( |
|
inputs=imgs, |
|
examples_per_page=10, |
|
examples=human_list_path |
|
) |
|
with gr.Column(): |
|
garm_img = gr.Image(label="Garment", sources='upload', type="filepath") |
|
example = gr.Examples( |
|
inputs=garm_img, |
|
examples_per_page=10, |
|
examples=garm_list_path) |
|
with gr.Column(): |
|
|
|
masked_img = gr.Image(label="Masked image output", elem_id="masked-img",show_share_button=False) |
|
with gr.Column(): |
|
|
|
image_out = gr.Image(label="Output", elem_id="output-img",show_share_button=False) |
|
with gr.Column(): |
|
try_button = gr.Button(value="predict") |
|
try_button.click(fn=predict, inputs=[imgs, garm_img], outputs=[image_out,masked_img]) |
|
image_blocks.launch() |