File size: 1,748 Bytes
ab92204
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import numpy as np
import gradio as gr
from Segmentation.segmentation import get_mask,replace_sofa
from StyleTransfer.styleTransfer import resize_sofa,resize_style,create_styledSofa
from PIL import Image

def style_sofa(input_img: np.ndarray, style_img: np.ndarray):
    """
    Styles (all) the sofas in the image to the given style.
    This function uses a transformer to combine the image with the desired style according 
    to a generated mask of the sofas in the image.
    Input:
        input_img = image containing a sofa
        style_img = image containing a style
    Return:
        new_sofa  = image containing the styled sofa
    """
    
    # preprocess input images to be (640,640) squares to fit requirements of the segmentation model
    resized_img = resize_sofa(input_img)
    resized_style = resize_style(style_img)
    # generate mask for image
    mask = get_mask(resized_img)
    styled_sofa = create_styledSofa(resized_img,resized_style)
    new_sofa = replace_sofa(resized_img,mask,styled_sofa)
    return new_sofa

image = gr.inputs.Image()
style = gr.inputs.Image()

demo = gr.Interface(
    style_sofa,
    [image,style],
    'image',
    examples=[
        ['input/sofa_example1.jpg','input/style_example1.jpg'],
        ['input/sofa_example1.jpg','input/style_example2.jpg'],
        ['input/sofa_example1.jpg','input/style_example3.jpg'],
        ['input/sofa_example1.jpg','input/style_example4.jpg'],
        ['input/sofa_example1.jpg','input/style_example5.jpg'],
    ],
    title="Style your sofa",
    description="πŸ›‹ Customize your sofa to your wildest dreams! πŸ›‹",
)

if __name__ == "__main__":
    demo.launch(share=True)


#https://github.com/dhawan98/Post-Processing-of-Image-Segmentation-using-CRF