mirror of
https://github.com/Sygil-Dev/sygil-webui.git
synced 2024-12-14 05:58:18 +03:00
more work on flet gallery
This commit is contained in:
parent
46ea2be0db
commit
e5a3a1b047
2
.gitignore
vendored
2
.gitignore
vendored
@ -67,7 +67,7 @@ condaenv.*.requirements.txt
|
||||
/flagged/*
|
||||
/gfpgan/*
|
||||
/models/*
|
||||
/webui/flet/uploads
|
||||
/webui/flet/assets/uploads/*
|
||||
|
||||
z_version_env.tmp
|
||||
scripts/bridgeData.py
|
||||
|
@ -9,76 +9,77 @@ from pprint import pprint
|
||||
|
||||
# logging
|
||||
def log_message(message):
|
||||
log_file = None
|
||||
# get time and format message
|
||||
prefix = datetime.now()
|
||||
msg_prefix = prefix.strftime("%Y/%m/%d %H:%M:%S")
|
||||
message = msg_prefix + " " + message
|
||||
# check to see if we're appending to current logfile or making a new one'
|
||||
try:
|
||||
log_file = log_message.log
|
||||
except AttributeError:
|
||||
log_prefix = prefix.strftime("%Y%m%d_%H%M%S")
|
||||
os.makedirs('log/webui/flet', exist_ok=True)
|
||||
log_message.log = os.path.join('log/webui/flet',log_prefix+'webui_flet.log')
|
||||
log_file = log_message.log
|
||||
# write message to logfile
|
||||
with open(log_file,'a+') as log:
|
||||
log.write(message)
|
||||
log_file = None
|
||||
# get time and format message
|
||||
prefix = datetime.now()
|
||||
msg_prefix = prefix.strftime("%Y/%m/%d %H:%M:%S")
|
||||
message = msg_prefix + " " + message
|
||||
# check to see if we're appending to current logfile or making a new one'
|
||||
try:
|
||||
log_file = log_message.log
|
||||
except AttributeError:
|
||||
log_prefix = prefix.strftime("%Y%m%d_%H%M%S")
|
||||
os.makedirs('log/webui/flet', exist_ok=True)
|
||||
log_message.log = os.path.join('log/webui/flet',log_prefix+'webui_flet.log')
|
||||
log_file = log_message.log
|
||||
# write message to logfile
|
||||
with open(log_file,'a+') as log:
|
||||
log.write(message)
|
||||
|
||||
# settings
|
||||
path_to_default_config = 'configs/webui/webui_flet.yaml'
|
||||
path_to_user_config = 'configs/webui/userconfig_flet.yaml'
|
||||
|
||||
def get_default_settings_from_config():
|
||||
with open(path_to_default_config) as f:
|
||||
default_settings = yaml.safe_load(f)
|
||||
return default_settings
|
||||
with open(path_to_default_config) as f:
|
||||
default_settings = yaml.safe_load(f)
|
||||
return default_settings
|
||||
|
||||
def get_user_settings_from_config():
|
||||
# get default settings
|
||||
settings = get_default_settings_from_config()
|
||||
# check to see if userconfig exists
|
||||
if os.path.exists(path_to_user_config):
|
||||
# compare to see which is newer
|
||||
default_time = os.path.getmtime(path_to_default_config)
|
||||
user_time = os.path.getmtime(path_to_user_config)
|
||||
# if default is newer, save over userconfig and exit early
|
||||
if (default_time > user_time):
|
||||
save_user_settings_to_config(settings)
|
||||
return settings
|
||||
# else, load userconfig
|
||||
with open(path_to_user_config) as f:
|
||||
user_settings = yaml.safe_load(f)
|
||||
settings.update(user_settings)
|
||||
# regardless, return settings as dict
|
||||
return settings
|
||||
# get default settings
|
||||
settings = get_default_settings_from_config()
|
||||
# check to see if userconfig exists
|
||||
if os.path.exists(path_to_user_config):
|
||||
# compare to see which is newer
|
||||
default_time = os.path.getmtime(path_to_default_config)
|
||||
user_time = os.path.getmtime(path_to_user_config)
|
||||
# if default is newer, save over userconfig and exit early
|
||||
if (default_time > user_time):
|
||||
save_user_settings_to_config(settings)
|
||||
return settings
|
||||
# else, load userconfig
|
||||
with open(path_to_user_config) as f:
|
||||
user_settings = yaml.safe_load(f)
|
||||
settings.update(user_settings)
|
||||
# regardless, return settings as dict
|
||||
return settings
|
||||
|
||||
def save_user_settings_to_config(settings):
|
||||
with open(path_to_user_config, 'w+') as f:
|
||||
yaml.dump(settings, f, default_flow_style=False)
|
||||
with open(path_to_user_config, 'w+') as f:
|
||||
yaml.dump(settings, f, default_flow_style=False)
|
||||
|
||||
|
||||
# image handling
|
||||
path_to_assets = "webui/flet/assets"
|
||||
path_to_uploads = "webui/flet/uploads"
|
||||
path_to_uploads = "webui/flet/assets/uploads"
|
||||
path_to_outputs = "webui/flet/assets/outputs"
|
||||
|
||||
# creates blank image (to do: take size as arg)
|
||||
def create_blank_image():
|
||||
img = Image.new('RGBA',(512,512),(0,0,0,0))
|
||||
return img
|
||||
img = Image.new('RGBA',(512,512),(0,0,0,0))
|
||||
return img
|
||||
|
||||
# takes name of image
|
||||
# returns dict
|
||||
# name of image : image handle
|
||||
def get_image_from_uploads(name):
|
||||
path_to_image = os.path.join(path_to_uploads, name)
|
||||
if os.path.exists(path_to_image):
|
||||
img = Image.open(path_to_image)
|
||||
return {name:img}
|
||||
else:
|
||||
log_message(f'image not found: "{name}"')
|
||||
return {name:None}
|
||||
path_to_image = os.path.join(path_to_uploads, name)
|
||||
if os.path.exists(path_to_image):
|
||||
img = Image.open(path_to_image)
|
||||
return {name:img}
|
||||
else:
|
||||
log_message(f'image not found: "{name}"')
|
||||
return {name:None}
|
||||
|
||||
|
||||
# takes name of gallery as arg ('assets','output','uploads')
|
||||
@ -87,23 +88,27 @@ def get_image_from_uploads(name):
|
||||
# 'img_path' : path_to_image
|
||||
# 'info_path' : path_to_yaml
|
||||
def get_gallery_images(gallery_name):
|
||||
path_to_gallery = None
|
||||
if gallery_name == 'uploads':
|
||||
path_to_gallery = path_to_uploads
|
||||
else:
|
||||
log_message(f'gallery not found: "{gallery_name}"')
|
||||
return None
|
||||
images = []
|
||||
files = os.listdir(path_to_gallery)
|
||||
for f in files:
|
||||
if f.endswith(('.jpg','.jpeg','.png')):
|
||||
path_to_file = os.path.join(path_to_gallery,f)
|
||||
images.append({f:{'img_path':path_to_file}})
|
||||
if f.endswith(('.yaml')):
|
||||
path_to_file = os.path.join(path_to_gallery,f)
|
||||
images.append({f:{'info_path':path_to_file}})
|
||||
#pprint(images)
|
||||
return images
|
||||
path_to_gallery = None
|
||||
if gallery_name == 'uploads':
|
||||
path_to_gallery = path_to_uploads
|
||||
elif gallery_name == 'outputs':
|
||||
path_to_gallery = path_to_outputs
|
||||
else:
|
||||
log_message(f'gallery not found: "{gallery_name}"')
|
||||
return None
|
||||
images = []
|
||||
files = []
|
||||
if os.path.exists(path_to_gallery):
|
||||
files = os.listdir(path_to_gallery)
|
||||
for f in files:
|
||||
if f.endswith(('.jpg','.jpeg','.png')):
|
||||
path_to_file = os.path.join('/uploads',f)
|
||||
images.append({f:{'img_path':path_to_file}})
|
||||
if f.endswith(('.yaml')):
|
||||
path_to_file = os.path.join('/uploads',f)
|
||||
images.append({f:{'info_path':path_to_file}})
|
||||
#pprint(images)
|
||||
return images
|
||||
|
||||
|
||||
# textual inversion
|
||||
@ -112,4 +117,4 @@ textual_inversion_grid_row_list = [
|
||||
]
|
||||
|
||||
def run_textual_inversion(args):
|
||||
pass
|
||||
pass
|
||||
|
@ -121,7 +121,6 @@ def main(page: ft.Page):
|
||||
page.update()
|
||||
|
||||
def open_gallery_window(e):
|
||||
init_gallery_display_images()
|
||||
page.dialog = gallery_window
|
||||
gallery_window.open = True
|
||||
page.update()
|
||||
@ -129,8 +128,43 @@ def main(page: ft.Page):
|
||||
def get_gallery_images(gallery_name):
|
||||
return flet_utils.get_gallery_images(gallery_name)
|
||||
|
||||
def init_gallery_display_images():
|
||||
gallery = gallery_window.current_gallery
|
||||
def refresh_gallery_images(gallery_name):
|
||||
gallery_display = ft.Stack(
|
||||
[
|
||||
ft.Row(
|
||||
controls = None,
|
||||
wrap = False,
|
||||
scroll = 'always',
|
||||
expand = True,
|
||||
),
|
||||
ft.Column(
|
||||
controls = [
|
||||
ft.Row(
|
||||
controls = [
|
||||
ft.IconButton(
|
||||
height = page.height * 0.75,
|
||||
icon_size = 50,
|
||||
content = ft.Icon(ft.icons.ARROW_CIRCLE_LEFT_OUTLINED),
|
||||
tooltip = 'last image',
|
||||
on_click = None,
|
||||
),
|
||||
ft.IconButton(
|
||||
height = page.height * 0.75,
|
||||
icon_size = 50,
|
||||
content = ft.Icon(ft.icons.ARROW_CIRCLE_RIGHT_OUTLINED),
|
||||
tooltip = 'next image',
|
||||
on_click = None,
|
||||
),
|
||||
],
|
||||
expand = True,
|
||||
alignment = 'spaceBetween',
|
||||
),
|
||||
],
|
||||
alignment = 'center',
|
||||
),
|
||||
],
|
||||
)
|
||||
gallery = get_gallery_images(gallery_name)
|
||||
for i in range(len(gallery)):
|
||||
image = gallery[i]
|
||||
image_name = list(image.keys())[0]
|
||||
@ -145,44 +179,9 @@ def main(page: ft.Page):
|
||||
gapless_playback = True,
|
||||
)
|
||||
)
|
||||
return gallery_display
|
||||
|
||||
|
||||
gallery_display = ft.Stack(
|
||||
[
|
||||
ft.Row(
|
||||
controls = None,
|
||||
wrap = False,
|
||||
scroll = 'always',
|
||||
expand = True,
|
||||
),
|
||||
ft.Column(
|
||||
controls = [
|
||||
ft.Row(
|
||||
controls = [
|
||||
ft.IconButton(
|
||||
height = page.height * 0.75,
|
||||
icon_size = 50,
|
||||
content = ft.Icon(ft.icons.ARROW_CIRCLE_LEFT_OUTLINED),
|
||||
tooltip = 'last image',
|
||||
on_click = None,
|
||||
),
|
||||
ft.IconButton(
|
||||
height = page.height * 0.75,
|
||||
icon_size = 50,
|
||||
content = ft.Icon(ft.icons.ARROW_CIRCLE_RIGHT_OUTLINED),
|
||||
tooltip = 'next image',
|
||||
on_click = None,
|
||||
),
|
||||
],
|
||||
expand = True,
|
||||
alignment = 'spaceBetween',
|
||||
),
|
||||
],
|
||||
alignment = 'center',
|
||||
),
|
||||
],
|
||||
)
|
||||
|
||||
gallery_window = GalleryWindow(
|
||||
title = ft.Text('Gallery'),
|
||||
content = ft.Container(
|
||||
@ -193,11 +192,11 @@ def main(page: ft.Page):
|
||||
tabs = [
|
||||
ft.Tab(
|
||||
text = "Uploads",
|
||||
content = gallery_display,
|
||||
content = refresh_gallery_images('uploads'),
|
||||
),
|
||||
ft.Tab(
|
||||
text = "Output",
|
||||
content = gallery_display,
|
||||
text = "Outputs",
|
||||
content = refresh_gallery_images('outputs'),
|
||||
),
|
||||
],
|
||||
),
|
||||
@ -217,10 +216,6 @@ def main(page: ft.Page):
|
||||
actions_alignment="end",
|
||||
)
|
||||
|
||||
gallery_window.uploads = get_gallery_images('uploads')
|
||||
gallery_window.current_gallery = gallery_window.uploads
|
||||
gallery_window.current_image_position = 0
|
||||
|
||||
|
||||
# upload window ######################################################
|
||||
def close_upload_window(e):
|
||||
@ -239,7 +234,7 @@ def main(page: ft.Page):
|
||||
upload_url = page.get_upload_url(f.name, 600)
|
||||
img = ft.FilePickerUploadFile(f.name,upload_url)
|
||||
file_list.append(img)
|
||||
file_picker.upload(file_list)
|
||||
file_picker.upload(file_list)
|
||||
|
||||
def upload_complete(e):
|
||||
progress_bars.clear()
|
||||
@ -685,7 +680,7 @@ def main(page: ft.Page):
|
||||
spacing = 0,
|
||||
scroll = 'auto',
|
||||
auto_scroll = True,
|
||||
controls = [],
|
||||
controls = [],
|
||||
)
|
||||
messages_window = ft.Container(
|
||||
bgcolor = ft.colors.BLACK12,
|
||||
@ -816,7 +811,7 @@ def main(page: ft.Page):
|
||||
# textual inversion layout properties
|
||||
def set_clip_model(e):
|
||||
pass
|
||||
|
||||
|
||||
clip_model_menu = ft.Dropdown(
|
||||
label = "Clip Model",
|
||||
value = 0,
|
||||
@ -1011,7 +1006,7 @@ def main(page: ft.Page):
|
||||
current_layout,
|
||||
],
|
||||
)
|
||||
|
||||
|
||||
|
||||
# make page ##########################################################
|
||||
full_page = ft.Stack(
|
||||
@ -1029,4 +1024,4 @@ def main(page: ft.Page):
|
||||
|
||||
layer_manager.update_layers()
|
||||
|
||||
ft.app(target=main, port= 8505, assets_dir="assets", upload_dir="uploads")
|
||||
ft.app(target=main, port= 8505, assets_dir="assets", upload_dir="assets/uploads")
|
||||
|
Loading…
Reference in New Issue
Block a user