-
Notifications
You must be signed in to change notification settings - Fork 1
/
loading_images_example.py
44 lines (31 loc) · 1.28 KB
/
loading_images_example.py
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
from app import db
import os
import base64
def get_base64_string(image_path):
with open(image_path, "rb") as image:
return base64.b64encode(image.read())
subfolders = ['Clothing', 'Food', 'Home', 'Nature', 'Sport']
for subfolder in subfolders:
images = os.listdir(f'Images/{subfolder}')
images = [img for img in images if img.endswith('.best.png')]
for img in images:
image_string = get_base64_string(f'Images/{subfolder}/{img}')
prompt = img.split('--')[0].replace('_', ' ')
theme = subfolder
print(theme, prompt)
db.write_image_to_db(prompt,
image_string.decode('utf-8'),
image_source='BigSleep',
theme=theme)
images = os.listdir(f'Images/misc')
for img in images:
image_string = get_base64_string(f'Images/misc/{img}')
prompt = img.split('.')[0].replace('_', ' ')
if 'siren' in prompt:
prompt = prompt.split(' siren')[0]
print(prompt)
image_source = 'Siren' if 'siren' in img else 'BigSleep'
db.write_image_to_db(prompt,
image_string.decode('utf-8'),
image_source=image_source,
theme='General')