Spaces:
Build error
Build error
Sophie98
commited on
Commit
•
88c5e7a
1
Parent(s):
f8f2e6b
fix automatic orientation phone
Browse files
app.py
CHANGED
@@ -3,11 +3,29 @@ from typing import Tuple
|
|
3 |
|
4 |
import gradio as gr
|
5 |
import numpy as np
|
6 |
-
from PIL import Image
|
7 |
|
8 |
from Segmentation.segmentation import get_mask, replace_sofa
|
9 |
from StyleTransfer.styleTransfer import create_styledSofa
|
10 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
11 |
|
12 |
def resize_sofa(img: Image.Image) -> Tuple[Image.Image, tuple]:
|
13 |
"""
|
@@ -105,8 +123,8 @@ def style_sofa(
|
|
105 |
print("Starting job ", id)
|
106 |
# preprocess input images to fit requirements of the segmentation model
|
107 |
input_img, style_img = Image.fromarray(Input_image), Image.fromarray(Style_image)
|
108 |
-
resized_img, box = resize_sofa(input_img)
|
109 |
-
resized_style = resize_style(style_img)
|
110 |
# resized_style.save('resized_style.jpg')
|
111 |
# generate mask for image
|
112 |
print("generating mask...")
|
@@ -177,10 +195,7 @@ demo = gr.Interface(
|
|
177 |
target='_blank'> \
|
178 |
4. A tensorflow model for fast arbitrary image style transfer. \
|
179 |
</a> \n"
|
180 |
-
"<a href='https://github.com/PaddlePaddle/PaddleHub/tree/release/v2.2/modules/image/Image_gan/style_transfer/stylepro_artistic' \
|
181 |
-
target='_blank'> \
|
182 |
-
5. A paddleHub model for parameter free style transfer. \
|
183 |
-
</a> \n",
|
184 |
)
|
185 |
|
186 |
if __name__ == "__main__":
|
|
|
3 |
|
4 |
import gradio as gr
|
5 |
import numpy as np
|
6 |
+
from PIL import Image, ExifTags
|
7 |
|
8 |
from Segmentation.segmentation import get_mask, replace_sofa
|
9 |
from StyleTransfer.styleTransfer import create_styledSofa
|
10 |
|
11 |
+
def fix_orient(img: Image.Image) -> Image.Image:
|
12 |
+
for orientation in ExifTags.TAGS.keys():
|
13 |
+
if ExifTags.TAGS[orientation]=='Orientation':
|
14 |
+
break
|
15 |
+
info=img._getexif()
|
16 |
+
if (info):
|
17 |
+
info = dict(info.items())
|
18 |
+
orientation = info[orientation]
|
19 |
+
if (orientation == 1) | (orientation == 2):
|
20 |
+
img = img
|
21 |
+
if (orientation == 3) | (orientation == 4):
|
22 |
+
img = img.rotate(180,expand=True)
|
23 |
+
if (orientation == 5) | (orientation == 6):
|
24 |
+
img = img.rotate(270,expand=True)
|
25 |
+
if (orientation == 7) | (orientation == 8):
|
26 |
+
img = img.rotate(90,expand=True)
|
27 |
+
return img
|
28 |
+
|
29 |
|
30 |
def resize_sofa(img: Image.Image) -> Tuple[Image.Image, tuple]:
|
31 |
"""
|
|
|
123 |
print("Starting job ", id)
|
124 |
# preprocess input images to fit requirements of the segmentation model
|
125 |
input_img, style_img = Image.fromarray(Input_image), Image.fromarray(Style_image)
|
126 |
+
resized_img, box = resize_sofa(fix_orient(input_img))
|
127 |
+
resized_style = resize_style(fix_orient(style_img))
|
128 |
# resized_style.save('resized_style.jpg')
|
129 |
# generate mask for image
|
130 |
print("generating mask...")
|
|
|
195 |
target='_blank'> \
|
196 |
4. A tensorflow model for fast arbitrary image style transfer. \
|
197 |
</a> \n"
|
198 |
+
"<a href='https://github.com/PaddlePaddle/PaddleHub/tree/release/v2.2/modules/image/Image_gan/style_transfer/stylepro_artistic' target='_blank'> 5. A paddleHub model for parameter free style transfer. </a> \n", # noqa
|
|
|
|
|
|
|
199 |
)
|
200 |
|
201 |
if __name__ == "__main__":
|