Spaces:
Build error
Build error
Your Name commited on
Commit ·
3d3e65e
1
Parent(s): 23faa2e
fix requirements
Browse filesFiles changed (2)
- app.py+18-11
- requirements.txt+3-1
1231 unmodified line56789101149 unmodified lines61626364656667686911 unmodified lines8182838485868710 unmodified lines98991001011021031041051061071081091101111121131141151161171181193 unmodified lines123124125126127128129import osfrom io import BytesIO1 unmodified lineimport grpcfrom PIL import Imagefrom cachetools import LRUCacheimport hashlibfrom inference_pb2 import HairSwapRequest, HairSwapResponsefrom inference_pb2_grpc import HairSwapServiceStub49 unmodified linesreturn resize_innerdef swap_hair(face, shape, color, blending, poisson_iters, poisson_erosion, progress=gr.Progress(track_tqdm=True)):if not face or not shape and not color:raise ValueError("Need to upload a face and at least a shape or color")face_bytes, shape_bytes, color_bytes = map(lambda item: get_bytes(item), (face, shape, color))11 unmodified lines)output = bytes_to_image(output.image)return outputdef get_demo():10 unmodified lines)with gr.Row():with gr.Column():source = gr.Image(label="Photo that you want to replace the hair", type="pil")with gr.Row():shape = gr.Image(label="Reference hair you want to get (optional)", type="pil")color = gr.Image(label="Reference color hair you want to get (optional)", type="pil")with gr.Accordion("Advanced Options", open=False):blending = gr.Radio(["Article", "Alternative_v1", "Alternative_v2"], value='Article',label="Blending version", info="Selects a model for hair color transfer.")poisson_iters = gr.Slider(0, 2500, value=0, step=1, label="Poisson iters",info="The power of blending with the original image, helps to recover more details. Not included in the article, disabled by default.")poisson_erosion = gr.Slider(1, 100, value=15, step=1, label="Poisson erosion",info="Smooths out the blending area.")align = gr.CheckboxGroup(["Face", "Shape", "Color"], value=["Face", "Shape", "Color"],label="Image cropping [recommended]", info="Selects which images to crop by face")btn = gr.Button("Get the haircut")with gr.Column():output = gr.Image(label="Your result")gr.Examples(examples=[["input/0.png", "input/1.png", "input/2.png"], ["input/6.png", "input/7.png", None],["input/10.jpg", None, "input/11.jpg"]],3 unmodified linesshape.upload(fn=resize('Shape'), inputs=[shape, align], outputs=shape)color.upload(fn=resize('Color'), inputs=[color, align], outputs=color)btn.click(fn=swap_hair, inputs=[source, shape, color, blending, poisson_iters, poisson_erosion], outputs=output)gr.Markdown('''To cite the paper by the authors```12341 unmodified line6789101149 unmodified lines6162636465666768697071727311 unmodified lines8586878889909110 unmodified lines1021031041051061071081091101111121131141151161171181191201211221231241253 unmodified lines129130131132133134135136import hashlibimport osfrom io import BytesIO1 unmodified lineimport grpcfrom PIL import Imagefrom cachetools import LRUCachefrom inference_pb2 import HairSwapRequest, HairSwapResponsefrom inference_pb2_grpc import HairSwapServiceStub49 unmodified linesreturn resize_innerdef swap_hair(face, shape, color, blending, poisson_iters, poisson_erosion):if not face and not shape and not color:return gr.update(visible=False), gr.update(value="Need to upload a face and at least a shape or color ❗", visible=True)elif not face:return gr.update(visible=False), gr.update(value="Need to upload a face ❗", visible=True)elif not shape and not color:return gr.update(visible=False), gr.update(value="Need to upload at least a shape or color ❗", visible=True)face_bytes, shape_bytes, color_bytes = map(lambda item: get_bytes(item), (face, shape, color))11 unmodified lines)output = bytes_to_image(output.image)return gr.update(value=output, visible=True), gr.update(visible=False)def get_demo():10 unmodified lines)with gr.Row():with gr.Column():source = gr.Image(label="Source photo to try on the hairstyle", type="pil")with gr.Row():shape = gr.Image(label="Shape photo with desired hairstyle (optional)", type="pil")color = gr.Image(label="Color photo with desired hair color (optional)", type="pil")with gr.Accordion("Advanced Options", open=False):blending = gr.Radio(["Article", "Alternative_v1", "Alternative_v2"], value='Article',label="Color Encoder version", info="Selects a model for hair color transfer.")poisson_iters = gr.Slider(0, 2500, value=0, step=1, label="Poisson iters",info="The power of blending with the original image, helps to recover more details. Not included in the article, disabled by default.")poisson_erosion = gr.Slider(1, 100, value=15, step=1, label="Poisson erosion",info="Smooths out the blending area.")align = gr.CheckboxGroup(["Face", "Shape", "Color"], value=["Face", "Shape", "Color"],label="Image cropping [recommended]",info="Selects which images to crop by face")btn = gr.Button("Get the haircut")with gr.Column():output = gr.Image(label="Your result")error_message = gr.Textbox(label="⚠️ Error ⚠️", visible=False, elem_classes="error-message")gr.Examples(examples=[["input/0.png", "input/1.png", "input/2.png"], ["input/6.png", "input/7.png", None],["input/10.jpg", None, "input/11.jpg"]],3 unmodified linesshape.upload(fn=resize('Shape'), inputs=[shape, align], outputs=shape)color.upload(fn=resize('Color'), inputs=[color, align], outputs=color)btn.click(fn=swap_hair, inputs=[source, shape, color, blending, poisson_iters, poisson_erosion],outputs=[output, error_message])gr.Markdown('''To cite the paper by the authors```
2 unmodified lines34562 unmodified linesaddict==2.4.0git+https://github.com/openai/CLIP.gitgdown==3.12.2dlib==19.24.12 unmodified lines3456782 unmodified linesaddict==2.4.0git+https://github.com/openai/CLIP.gitgdown==3.12.2grpcio==1.63.0grpcio_tools=1.63.0gradio=4.31.5
app.py+18-11
requirements.txt+3-1