Spaces:
Sleeping
Sleeping
AntaresGuo
commited on
Upload data_convert.py
Browse files- utils/data_convert.py +15 -0
utils/data_convert.py
ADDED
@@ -0,0 +1,15 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import base64
|
2 |
+
from io import BytesIO
|
3 |
+
|
4 |
+
# pip3 install pillow
|
5 |
+
from PIL import Image
|
6 |
+
import re
|
7 |
+
|
8 |
+
|
9 |
+
def base64_to_image(base64_str):
|
10 |
+
base64_data = re.sub('^data:image/.+;base64,', '', base64_str)
|
11 |
+
byte_data = base64.b64decode(base64_data)
|
12 |
+
image_data = BytesIO(byte_data)
|
13 |
+
img = Image.open(image_data)
|
14 |
+
|
15 |
+
return img
|