Spaces:
Runtime error
Runtime error
lixiang46 commited on
Commit ·
f69cd15
1
Parent(s): fe70090
init
Browse filesFiles changed (29)
- .gitattributes+3
- README.md+2-2
- app.py+51-126
- assets/cloth/04469_00.jpgAdded
- assets/cloth/04743_00.jpgAdded
- assets/cloth/09133_00.jpgAdded
- assets/cloth/09163_00.jpgAdded
- assets/cloth/09164_00.jpgAdded
- assets/cloth/09166_00.jpgAdded
- assets/cloth/09176_00.jpgAdded
- assets/cloth/09236_00.jpgAdded
- assets/cloth/09256_00.jpgAdded
- assets/cloth/09263_00.jpgAdded
- assets/cloth/09266_00.jpgAdded
- assets/cloth/09290_00.jpgAdded
- assets/cloth/09305_00.jpgAdded
- assets/cloth/10165_00.jpgAdded
- assets/cloth/14627_00.jpgAdded
- assets/cloth/14673_00.jpgAdded
- assets/human/00034_00.jpgAdded
- assets/human/00035_00.jpgAdded
- assets/human/00055_00.jpgAdded
- assets/human/00121_00.jpgAdded
- assets/human/01992_00.jpgAdded
- assets/human/Jensen.jpegAdded
- assets/human/sam1 (1).jpgAdded
- assets/human/taylor-.jpgAdded
- assets/human/will1 (1).jpgAdded
- assets/title.mdAdded+3
32 unmodified lines33343532 unmodified lines*.zip filter=lfs diff=lfs merge=lfs -text*.zst filter=lfs diff=lfs merge=lfs -text*tfevents* filter=lfs diff=lfs merge=lfs -text32 unmodified lines33343536373832 unmodified lines*.zip filter=lfs diff=lfs merge=lfs -text*.zst filter=lfs diff=lfs merge=lfs -text*tfevents* filter=lfs diff=lfs merge=lfs -textassets/cloth filter=lfs diff=lfs merge=lfs -textassets/human filter=lfs diff=lfs merge=lfs -textassets/title.md filter=lfs diff=lfs merge=lfs -text
1 unmodified line23456789101 unmodified linetitle: Kolors Tryonemoji: 🖼colorFrom: purplecolorTo: redsdk: gradiosdk_version: 4.26.0app_file: app.pypinned: falselicense: apache-2.01 unmodified line23456789101 unmodified linetitle: Kolors Tryonemoji: 🖼colorFrom: purplecolorTo: graysdk: gradiosdk_version: 4.38.1app_file: app.pypinned: falselicense: apache-2.0
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146import gradio as grimport numpy as npimport randomfrom diffusers import DiffusionPipelineimport torchdevice = "cuda" if torch.cuda.is_available() else "cpu"if torch.cuda.is_available():torch.cuda.max_memory_allocated(device=device)pipe = DiffusionPipeline.from_pretrained("stabilityai/sdxl-turbo", torch_dtype=torch.float16, variant="fp16", use_safetensors=True)pipe.enable_xformers_memory_efficient_attention()pipe = pipe.to(device)else:pipe = DiffusionPipeline.from_pretrained("stabilityai/sdxl-turbo", use_safetensors=True)pipe = pipe.to(device)MAX_SEED = np.iinfo(np.int32).maxMAX_IMAGE_SIZE = 1024def infer(prompt, negative_prompt, seed, randomize_seed, width, height, guidance_scale, num_inference_steps):if randomize_seed:seed = random.randint(0, MAX_SEED)generator = torch.Generator().manual_seed(seed)image = pipe(prompt = prompt,negative_prompt = negative_prompt,guidance_scale = guidance_scale,num_inference_steps = num_inference_steps,width = width,height = height,generator = generator).images[0]return imageexamples = ["Astronaut in a jungle, cold color palette, muted colors, detailed, 8k","An astronaut riding a green horse","A delicious ceviche cheesecake slice",]css="""#col-container {margin: 0 auto;max-width: 520px;}"""if torch.cuda.is_available():power_device = "GPU"else:power_device = "CPU"with gr.Blocks(css=css) as demo:with gr.Column(elem_id="col-container"):gr.Markdown(f"""# Text-to-Image Gradio TemplateCurrently running on {power_device}.""")with gr.Row():prompt = gr.Text(label="Prompt",show_label=False,max_lines=1,placeholder="Enter your prompt",container=False,)run_button = gr.Button("Run", scale=0)result = gr.Image(label="Result", show_label=False)with gr.Accordion("Advanced Settings", open=False):negative_prompt = gr.Text(label="Negative prompt",max_lines=1,placeholder="Enter a negative prompt",visible=False,)seed = gr.Slider(label="Seed",minimum=0,maximum=MAX_SEED,step=1,value=0,)randomize_seed = gr.Checkbox(label="Randomize seed", value=True)with gr.Row():width = gr.Slider(label="Width",minimum=256,maximum=MAX_IMAGE_SIZE,step=32,value=512,)height = gr.Slider(label="Height",minimum=256,maximum=MAX_IMAGE_SIZE,step=32,value=512,)with gr.Row():guidance_scale = gr.Slider(label="Guidance scale",minimum=0.0,maximum=10.0,step=0.1,value=0.0,)num_inference_steps = gr.Slider(label="Number of inference steps",minimum=1,maximum=12,step=1,value=2,)gr.Examples(examples = examples,inputs = [prompt])run_button.click(fn = infer,inputs = [prompt, negative_prompt, seed, randomize_seed, width, height, guidance_scale, num_inference_steps],outputs = [result])demo.queue().launch()1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071import sysimport osimport iofrom PIL import Imageimport gradio as grimport numpy as npimport randomexample_path = os.path.join(os.path.dirname(__file__), 'assets')MAX_SEED = 999999def start_tryon(imgs, garm_img, garment_des, seed):return Nonegarm_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]css="""#col-left {margin: 0 auto;max-width: 600px;}#col-right {margin: 0 auto;max-width: 750px;}#button {color: blue;}"""def load_description(fp):with open(fp, 'r', encoding='utf-8') as f:content = f.read()return contentwith gr.Blocks(css=css) as Tryon:gr.HTML(load_description("assets/title.md"))with gr.Row():with gr.Column():imgs = gr.Image(label="Person image", sources='upload', type="pil")# category = gr.Dropdown(label="Garment category", choices=['upper_body', 'lower_body', 'dresses'], value="upper_body")example = gr.Examples(inputs=imgs,examples_per_page=10,examples=human_list_path)with gr.Column():garm_img = gr.Image(label="Garment image", sources='upload', type="pil")example = gr.Examples(inputs=garm_img,examples_per_page=8,examples=garm_list_path)with gr.Column():image_out = gr.Image(label="Output", elem_id="output-img",show_share_button=False)try_button = gr.Button(value="Try-on")with gr.Column():with gr.Accordion(label="Advanced Settings", open=False):with gr.Row():seed = gr.Number(label="Seed", minimum=-1, maximum=2147483647, step=1, value=None)try_button.click(fn=start_tryon, inputs=[imgs, garm_img, seed], outputs=[image_out], api_name='tryon')Tryon.queue(max_size=10).launch()
123version https://git-lfs.github.com/spec/v1oid sha256:ee7fff5b3874ec80927627cdec9b2e5773cf257952b81fd280c4458993dc1894size 598.gitattributes+3
README.md+2-2
app.py+51-126
assets/cloth/04469_00.jpgAdded

assets/cloth/04743_00.jpgAdded

assets/cloth/09133_00.jpgAdded

assets/cloth/09163_00.jpgAdded

assets/cloth/09164_00.jpgAdded

assets/cloth/09166_00.jpgAdded

assets/cloth/09176_00.jpgAdded

assets/cloth/09236_00.jpgAdded

assets/cloth/09256_00.jpgAdded

assets/cloth/09263_00.jpgAdded

assets/cloth/09266_00.jpgAdded

assets/cloth/09290_00.jpgAdded

assets/cloth/09305_00.jpgAdded

assets/cloth/10165_00.jpgAdded

assets/cloth/14627_00.jpgAdded

assets/cloth/14673_00.jpgAdded

assets/human/00034_00.jpgAdded

assets/human/00035_00.jpgAdded

assets/human/00055_00.jpgAdded

assets/human/00121_00.jpgAdded

assets/human/01992_00.jpgAdded

assets/human/Jensen.jpegAdded

assets/human/sam1 (1).jpgAdded
.jpg)
assets/human/taylor-.jpgAdded

assets/human/will1 (1).jpgAdded
.jpg)
assets/title.mdAdded+3