Sophie98 commited on
Commit
3dacec1
β€’
1 Parent(s): de4d926
Files changed (1) hide show
  1. app.py +50 -0
app.py ADDED
@@ -0,0 +1,50 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import numpy as np
2
+ import gradio as gr
3
+ from segmentation import get_mask,replace_sofa
4
+ from styleTransfer import resize_sofa,resize_style,create_styledSofa
5
+ from PIL import Image
6
+
7
+ def style_sofa(input_img: np.ndarray, style_img: np.ndarray):
8
+ """
9
+ Styles (all) the sofas in the image to the given style.
10
+ This function uses a transformer to combine the image with the desired style according
11
+ to a generated mask of the sofas in the image.
12
+ Input:
13
+ input_img = image containing a sofa
14
+ style_img = image containing a style
15
+ Return:
16
+ new_sofa = image containing the styled sofa
17
+ """
18
+
19
+ # preprocess input images to be (640,640) squares to fit requirements of the segmentation model
20
+ resized_img = resize_sofa(input_img)
21
+ resized_style = resize_style(style_img)
22
+ # generate mask for image
23
+ mask = get_mask(resized_img)
24
+ styled_sofa = create_styledSofa(resized_img,resized_style)
25
+ new_sofa = replace_sofa(resized_img,mask,styled_sofa)
26
+ return new_sofa
27
+
28
+ image = gr.inputs.Image()
29
+ style = gr.inputs.Image()
30
+
31
+ demo = gr.Interface(
32
+ style_sofa,
33
+ [image,style],
34
+ 'image',
35
+ examples=[
36
+ ['sofa_example1.jpg','style_example1.jpg'],
37
+ ['sofa_example1.jpg','style_example2.jpg'],
38
+ ['sofa_example1.jpg','style_example3.jpg'],
39
+ ['sofa_example1.jpg','style_example4.jpg'],
40
+ ['sofa_example1.jpg','style_example5.jpg'],
41
+ ],
42
+ title="Style your sofa",
43
+ description="πŸ›‹ Customize your sofa to your wildest dreams! πŸ›‹",
44
+ )
45
+
46
+ if __name__ == "__main__":
47
+ demo.launch(share=True)
48
+
49
+
50
+ #https://github.com/dhawan98/Post-Processing-of-Image-Segmentation-using-CRF