2022-11-16 13:03:44 +03:00
# Flet imports
import flet as ft
2022-11-19 21:10:13 +03:00
from flet . ref import Ref
2022-11-16 13:03:44 +03:00
# other imports
from math import pi
from typing import Optional
from loguru import logger
2022-11-19 21:10:13 +03:00
# utils imports
2022-11-21 00:11:50 +03:00
import webui_flet_utils
2022-11-16 13:03:44 +03:00
2022-11-19 21:10:13 +03:00
# for debugging
from pprint import pprint
2022-11-16 13:03:44 +03:00
@logger.catch ( reraise = True )
def main ( page : ft . Page ) :
2022-11-23 04:29:14 +03:00
# main function defines
2022-11-21 00:11:50 +03:00
2022-11-22 00:28:48 +03:00
def load_settings ( ) :
settings = webui_flet_utils . get_user_settings_from_config ( )
page . session . set ( ' settings ' , settings )
page . update ( )
def save_settings_to_config ( ) :
settings = page . session . get ( ' settings ' )
webui_flet_utils . save_user_settings_to_config ( settings )
def reset_settings_from_config ( ) :
settings = webui_flet_utils . get_default_settings_from_config ( )
page . session . remove ( ' settings ' )
page . session . set ( ' settings ' , settings )
save_settings_to_config ( )
2022-11-17 00:11:43 +03:00
def change_theme ( e ) :
page . theme_mode = " dark " if page . theme_mode == " light " else " light "
if " (Light theme) " in theme_switcher . tooltip :
theme_switcher . tooltip = theme_switcher . tooltip . replace ( " (Light theme) " , ' ' )
if " (Dark theme) " in theme_switcher . tooltip :
theme_switcher . tooltip = theme_switcher . tooltip . replace ( " (Dark theme) " , ' ' )
theme_switcher . tooltip + = " (Light theme) " if page . theme_mode == " light " else " (Dark theme) "
page . update ( )
2022-11-22 00:28:48 +03:00
2022-11-23 04:29:14 +03:00
# init ###############################################################
2022-11-22 00:28:48 +03:00
if not page . session . contains_key ( ' settings ' ) :
load_settings ( )
2022-11-23 04:29:14 +03:00
# layouts ############################################################
2022-11-19 21:10:13 +03:00
def change_layout ( e ) :
current_layout . value = e . control . data
set_current_layout_options ( e . control . data )
set_current_layout_tools ( e . control . data )
set_property_panel_options ( e . control . data )
page . update ( )
def set_current_layout_options ( layout ) :
for control in current_layout_options . controls :
current_layout_options . controls . pop ( )
2022-11-22 00:28:48 +03:00
if layout == ' Default ' :
current_layout_options . controls . append ( default_layout_options )
2022-11-19 21:10:13 +03:00
elif layout == ' Textual Inversion ' :
current_layout_options . controls . append ( textual_inversion_layout_options )
elif layout == ' Node Editor ' :
current_layout_options . controls . append ( node_editor_layout_options )
def set_current_layout_tools ( layout ) :
for control in current_layout_tools . controls :
current_layout_tools . controls . pop ( )
2022-11-22 00:28:48 +03:00
if layout == ' Default ' :
current_layout_tools . controls . append ( default_layout_tools )
2022-11-19 21:10:13 +03:00
elif layout == ' Textual Inversion ' :
current_layout_tools . controls . append ( textual_inversion_layout_tools )
elif layout == ' Node Editor ' :
current_layout_tools . controls . append ( node_editor_layout_tools )
def set_property_panel_options ( layout ) :
2022-11-21 00:11:50 +03:00
controls = property_panel . content . controls
for control in controls :
controls . pop ( )
2022-11-22 00:28:48 +03:00
if layout == ' Default ' :
controls . append ( default_layout_properties )
2022-11-19 21:10:13 +03:00
elif layout == ' Textual Inversion ' :
2022-11-21 00:11:50 +03:00
controls . append ( textual_inversion_layout_properties )
2022-11-19 21:10:13 +03:00
elif layout == ' Node Editor ' :
2022-11-21 00:11:50 +03:00
controls . append ( node_editor_layout_properties )
2022-11-19 21:10:13 +03:00
2022-11-23 04:29:14 +03:00
# settings window ####################################################
2022-11-17 00:11:43 +03:00
def close_settings_window ( e ) :
2022-11-22 00:28:48 +03:00
settings_window . open = False
2022-11-17 00:11:43 +03:00
page . update ( )
def open_settings_window ( e ) :
2022-11-22 00:28:48 +03:00
page . dialog = settings_window
settings_window . open = True
page . update ( )
2022-11-23 04:29:14 +03:00
def update_general_settings ( ) :
general_settings = get_general_settings ( )
general_settings_page . controls = general_settings
def update_ui_settings ( ) :
2022-11-22 00:28:48 +03:00
ui_settings = get_ui_settings ( )
2022-11-23 04:29:14 +03:00
ui_settings_page . controls = ui_settings
def update_settings ( ) :
update_general_settings ( )
update_ui_settings ( )
2022-11-17 00:11:43 +03:00
page . update ( )
2022-11-22 00:28:48 +03:00
def save_settings ( e ) :
save_settings_to_config ( )
update_settings ( )
def reset_settings ( e ) :
reset_settings_from_config ( )
update_settings ( )
2022-11-23 04:29:14 +03:00
def general_setting_changed ( e ) :
settings = page . session . get ( ' settings ' )
settings [ ' general ' ] [ e . control . label ] [ ' value ' ] = e . control . value
update_general_settings ( )
page . update ( )
2022-11-22 00:28:48 +03:00
def ui_setting_changed ( e ) :
settings = page . session . get ( ' settings ' )
settings [ ' webui ' ] [ e . control . label ] = e . control . value
2022-11-23 04:29:14 +03:00
update_ui_settings ( )
page . update ( )
def get_general_settings ( ) :
settings = page . session . get ( ' settings ' )
general_settings = [ ft . Divider ( height = 10 , color = ' gray ' ) ]
for setting in settings [ ' general ' ] :
if ' value ' not in settings [ ' general ' ] [ setting ] :
continue
display = None
display_type = settings [ ' general ' ] [ setting ] [ ' display ' ]
if display_type == ' dropdown ' :
option_list = [ ]
for i in range ( len ( settings [ ' general ' ] [ setting ] [ ' option_list ' ] ) ) :
item = ft . dropdown . Option (
text = settings [ ' general ' ] [ setting ] [ ' option_list ' ] [ i ]
)
option_list . append ( item )
display = ft . Dropdown (
label = setting ,
value = settings [ ' general ' ] [ setting ] [ ' value ' ] ,
options = option_list ,
on_change = general_setting_changed ,
)
elif display_type == ' slider ' :
display = ft . Slider (
label = setting ,
value = settings [ ' general ' ] [ setting ] [ ' value ' ] ,
min = settings [ ' general ' ] [ setting ] [ ' min ' ] ,
max = settings [ ' general ' ] [ setting ] [ ' max ' ] ,
on_change = general_setting_changed ,
)
elif display_type == ' textinput ' :
display = ft . TextField (
label = setting ,
value = settings [ ' general ' ] [ setting ] [ ' value ' ] ,
on_change = general_setting_changed ,
)
else :
continue
new_row = ft . Row (
controls = [
display ,
]
)
general_settings . append ( new_row )
return general_settings
2022-11-22 00:28:48 +03:00
def get_ui_settings ( ) :
settings = page . session . get ( ' settings ' )
ui_settings = [ ft . Divider ( height = 10 , color = " gray " ) ]
for setting in settings [ ' webui ' ] :
value = ft . TextField (
label = setting ,
value = settings [ ' webui ' ] [ setting ] ,
on_change = ui_setting_changed ,
)
new_row = ft . Row (
controls = [
value ,
]
)
ui_settings . append ( new_row )
return ui_settings
2022-11-23 04:29:14 +03:00
general_settings = get_general_settings ( )
2022-11-22 00:28:48 +03:00
general_settings_page = ft . Column (
2022-11-20 04:00:58 +03:00
alignment = ' start ' ,
2022-11-21 00:11:50 +03:00
scroll = ' auto ' ,
2022-11-23 04:29:14 +03:00
controls = general_settings ,
2022-11-20 04:00:58 +03:00
)
2022-11-22 00:28:48 +03:00
performance_settings_page = ft . Column (
2022-11-20 04:00:58 +03:00
alignment = ' start ' ,
2022-11-21 00:11:50 +03:00
scroll = ' auto ' ,
2022-11-20 04:00:58 +03:00
controls = [
ft . Divider ( height = 10 , color = " gray " ) ,
] ,
)
2022-11-22 00:28:48 +03:00
server_settings_page = ft . Column (
2022-11-20 04:00:58 +03:00
alignment = ' start ' ,
2022-11-21 00:11:50 +03:00
scroll = True ,
2022-11-20 04:00:58 +03:00
controls = [
ft . Divider ( height = 10 , color = " gray " ) ,
] ,
)
2022-11-22 00:28:48 +03:00
ui_settings = get_ui_settings ( )
ui_settings_page = ft . Column (
2022-11-20 04:00:58 +03:00
alignment = ' start ' ,
2022-11-21 00:11:50 +03:00
scroll = True ,
2022-11-22 00:28:48 +03:00
controls = ui_settings ,
2022-11-20 04:00:58 +03:00
)
2022-11-22 00:28:48 +03:00
settings_window = ft . AlertDialog (
2022-11-17 00:11:43 +03:00
#modal = True,
title = ft . Text ( " Settings " ) ,
2022-11-20 04:00:58 +03:00
content = ft . Container (
width = page . width * 0.50 ,
content = ft . Tabs (
selected_index = 0 ,
animation_duration = 300 ,
tabs = [
ft . Tab (
text = " General " ,
2022-11-22 00:28:48 +03:00
content = general_settings_page ,
2022-11-20 04:00:58 +03:00
) ,
ft . Tab (
text = " Performance " ,
2022-11-22 00:28:48 +03:00
content = performance_settings_page ,
2022-11-20 04:00:58 +03:00
) ,
ft . Tab (
text = " Server " ,
2022-11-22 00:28:48 +03:00
content = server_settings_page ,
2022-11-20 04:00:58 +03:00
) ,
ft . Tab (
text = " Interface " ,
2022-11-22 00:28:48 +03:00
content = ui_settings_page ,
2022-11-20 04:00:58 +03:00
) ,
] ,
) ,
2022-11-17 00:11:43 +03:00
) ,
actions = [
2022-11-22 00:28:48 +03:00
ft . ElevatedButton (
text = " Save " ,
icon = ft . icons . SAVE ,
on_click = save_settings ,
) ,
ft . ElevatedButton (
text = " Restore Defaults " ,
icon = ft . icons . RESTORE_FROM_TRASH_ROUNDED ,
on_click = reset_settings ,
) ,
2022-11-17 00:11:43 +03:00
] ,
actions_alignment = " end " ,
#on_dismiss=lambda e: print("Modal dialog dismissed!"),
)
2022-11-23 04:29:14 +03:00
# gallery window #####################################################
2022-11-19 21:10:13 +03:00
def close_gallery_window ( e ) :
2022-11-22 00:28:48 +03:00
gallery_window . open = False
2022-11-19 21:10:13 +03:00
page . update ( )
def open_gallery_window ( e ) :
2022-11-22 00:28:48 +03:00
page . dialog = gallery_window
gallery_window . open = True
2022-11-19 21:10:13 +03:00
page . update ( )
2022-11-22 00:28:48 +03:00
gallery_window = ft . AlertDialog (
2022-11-19 21:10:13 +03:00
title = ft . Text ( ' Gallery ' ) ,
content = ft . Row (
controls = [
ft . Text ( ' Working on it I swear... ' ) ,
ft . Container (
width = page . width * 0.75 ,
height = page . height * 0.75 ,
) ,
] ,
) ,
actions = [
2022-11-22 00:28:48 +03:00
ft . ElevatedButton (
text = " Save " ,
icon = ft . icons . SAVE ,
on_click = None ,
) ,
ft . ElevatedButton (
text = " Discard " ,
icon = ft . icons . RESTORE_FROM_TRASH_ROUNDED ,
on_click = None ,
) ,
2022-11-19 21:10:13 +03:00
] ,
actions_alignment = " end " ,
2022-11-17 00:11:43 +03:00
)
2022-11-23 04:29:14 +03:00
# app bar ############################################################
2022-11-21 00:11:50 +03:00
app_bar_title = ft . Text (
value = " Sygil " ,
2022-11-22 00:28:48 +03:00
size = 20 ,
2022-11-21 00:11:50 +03:00
text_align = ' center ' ,
)
prompt = ft . TextField (
value = " " ,
min_lines = 1 ,
max_lines = 1 ,
2022-11-23 04:29:14 +03:00
content_padding = 10 ,
#text_align="center",
2022-11-21 00:11:50 +03:00
shift_enter = True ,
tooltip = " Prompt to use for generation. " ,
autofocus = True ,
hint_text = " A corgi wearing a top hat as an oil painting. " ,
2022-11-22 00:28:48 +03:00
height = 50 ,
text_size = 20 ,
2022-11-21 00:11:50 +03:00
)
generate_button = ft . ElevatedButton (
text = " Generate " ,
on_click = None ,
2022-11-22 00:28:48 +03:00
height = 50 ,
2022-11-21 00:11:50 +03:00
)
2022-11-19 21:10:13 +03:00
2022-11-23 04:29:14 +03:00
layouts = ft . Dropdown (
options = [
ft . dropdown . Option ( text = " Default " ) ,
ft . dropdown . Option ( text = " Textual Inversion " ) ,
ft . dropdown . Option ( text = " Node Editor " ) ,
2022-11-19 21:10:13 +03:00
] ,
2022-11-23 04:29:14 +03:00
value = " Default " ,
content_padding = 10 ,
width = 200 ,
on_change = change_layout ,
2022-11-19 21:10:13 +03:00
tooltip = " Switch between different workspaces " ,
2022-11-22 00:28:48 +03:00
height = 50 ,
2022-11-19 21:10:13 +03:00
)
2022-11-23 04:29:14 +03:00
#current_layout = ft.Text(
#value = 'Default',
#size = 20,
#tooltip = "Current Workspace",
#)
2022-11-19 21:10:13 +03:00
layout_menu = ft . Row (
alignment = ' start ' ,
controls = [
ft . Container ( content = layouts ) ,
2022-11-23 04:29:14 +03:00
#ft.Container(content = current_layout),
2022-11-21 00:11:50 +03:00
] ,
2022-11-22 00:28:48 +03:00
height = 50 ,
2022-11-19 21:10:13 +03:00
)
2022-11-22 00:28:48 +03:00
default_layout_options = ft . Row (
2022-11-19 21:10:13 +03:00
alignment = ' start ' ,
controls = [
ft . Container ( ft . IconButton ( content = ft . Text ( value = ' Canvas ' ) , tooltip = ' Canvas Options ' , on_click = None , disabled = True ) ) ,
ft . Container ( ft . IconButton ( content = ft . Text ( value = ' Layers ' ) , tooltip = ' Layer Options ' , on_click = None , disabled = True ) ) ,
ft . Container ( ft . IconButton ( content = ft . Text ( value = ' Tools ' ) , tooltip = ' Toolbox ' , on_click = None , disabled = True ) ) ,
ft . Container ( ft . IconButton ( content = ft . Text ( value = ' Preferences ' ) , tooltip = ' Set Editor Preferences ' , on_click = None , disabled = True ) ) ,
2022-11-21 00:11:50 +03:00
] ,
2022-11-22 00:28:48 +03:00
height = 50 ,
2022-11-19 21:10:13 +03:00
)
textual_inversion_layout_options = ft . Row (
alignment = ' start ' ,
controls = [
ft . Container ( ft . IconButton ( content = ft . Icon ( ft . icons . ADD_OUTLINED ) , tooltip = ' textual_inversion options 1 ' , on_click = None , disabled = True ) ) ,
ft . Container ( ft . IconButton ( content = ft . Icon ( ft . icons . ADD_OUTLINED ) , tooltip = ' textual_inversion options 2 ' , on_click = None , disabled = True ) ) ,
ft . Container ( ft . IconButton ( content = ft . Icon ( ft . icons . ADD_OUTLINED ) , tooltip = ' textual_inversion options 3 ' , on_click = None , disabled = True ) ) ,
2022-11-21 00:11:50 +03:00
] ,
2022-11-22 00:28:48 +03:00
height = 50 ,
2022-11-19 21:10:13 +03:00
)
node_editor_layout_options = ft . Row (
alignment = ' start ' ,
controls = [
ft . Container ( ft . IconButton ( content = ft . Icon ( ft . icons . ADD_OUTLINED ) , tooltip = ' node_editor options 1 ' , on_click = None , disabled = True ) ) ,
ft . Container ( ft . IconButton ( content = ft . Icon ( ft . icons . ADD_OUTLINED ) , tooltip = ' node_editor options 2 ' , on_click = None , disabled = True ) ) ,
ft . Container ( ft . IconButton ( content = ft . Icon ( ft . icons . ADD_OUTLINED ) , tooltip = ' node_editor options 3 ' , on_click = None , disabled = True ) ) ,
2022-11-21 00:11:50 +03:00
] ,
2022-11-22 00:28:48 +03:00
height = 50 ,
2022-11-19 21:10:13 +03:00
)
current_layout_options = ft . Row (
alignment = ' start ' ,
controls = [
2022-11-22 00:28:48 +03:00
ft . Container ( content = default_layout_options ) ,
2022-11-21 00:11:50 +03:00
] ,
2022-11-22 00:28:48 +03:00
height = 50 ,
2022-11-19 21:10:13 +03:00
)
2022-11-17 00:11:43 +03:00
theme_switcher = ft . IconButton (
ft . icons . WB_SUNNY_OUTLINED ,
on_click = change_theme ,
expand = 1 ,
2022-11-21 00:11:50 +03:00
tooltip = f " Click to change between the light and dark themes. Current { ' (Light theme) ' if page . theme_mode == ' light ' else ' (Dark theme) ' } " ,
2022-11-22 00:28:48 +03:00
height = 50 ,
2022-11-17 00:11:43 +03:00
)
2022-11-21 00:11:50 +03:00
settings_button = ft . IconButton (
icon = ft . icons . SETTINGS ,
on_click = open_settings_window ,
2022-11-22 00:28:48 +03:00
height = 50 ,
2022-11-21 00:11:50 +03:00
)
2022-11-17 00:11:43 +03:00
2022-11-23 04:29:14 +03:00
#menu_button = ft.PopupMenuButton(
#items = [
##ft.PopupMenuItem(text="Settings", on_click=open_settings_modal),
#ft.PopupMenuItem(), # divider
##ft.PopupMenuItem(text="Checked item", checked=False, on_click=check_item_clicked),
#],
#height = 50,
#)
2022-11-17 00:11:43 +03:00
option_bar = ft . Row (
controls = [
2022-11-23 04:29:14 +03:00
#ft.Container(expand=True, content = current_layout_options),
2022-11-21 00:11:50 +03:00
ft . Container ( expand = 2 , content = layout_menu ) ,
2022-11-17 00:11:43 +03:00
ft . Container ( expand = 1 , content = theme_switcher ) ,
ft . Container ( expand = 1 , content = settings_button ) ,
2022-11-23 04:29:14 +03:00
#ft.Container(expand = 1, content = menu_button),
2022-11-21 00:11:50 +03:00
] ,
2022-11-22 00:28:48 +03:00
height = 50 ,
2022-11-17 00:11:43 +03:00
)
appbar = ft . Row (
width = page . width ,
controls = [
2022-11-21 00:11:50 +03:00
ft . Container ( content = app_bar_title ) ,
2022-11-19 21:10:13 +03:00
ft . VerticalDivider ( width = 20 , opacity = 0 ) ,
2022-11-21 00:11:50 +03:00
ft . Container ( expand = 6 , content = prompt ) ,
2022-11-23 04:29:14 +03:00
#ft.Container(expand = 1, content = generate_button),
2022-11-21 00:11:50 +03:00
ft . Container ( expand = 4 , content = option_bar ) ,
2022-11-17 00:11:43 +03:00
] ,
2022-11-22 00:28:48 +03:00
height = 50 ,
2022-11-17 00:11:43 +03:00
)
2022-11-23 04:29:14 +03:00
# toolbar ############################################################
2022-11-22 00:28:48 +03:00
open_gallery_button = ft . IconButton ( width = 50 , content = ft . Icon ( ft . icons . DASHBOARD_OUTLINED ) , tooltip = ' Gallery ' , on_click = open_gallery_window )
import_image_button = ft . IconButton ( width = 50 , content = ft . Icon ( ft . icons . ADD_OUTLINED ) , tooltip = ' Import image as new layer ' , on_click = None )
2022-11-21 00:11:50 +03:00
2022-11-19 21:10:13 +03:00
universal_tools = ft . Row (
alignment = ' start ' ,
2022-11-22 00:28:48 +03:00
width = 50 ,
2022-11-19 21:10:13 +03:00
wrap = True ,
controls = [
open_gallery_button ,
import_image_button ,
]
)
2022-11-23 04:29:14 +03:00
# default layout tools
2022-11-22 00:28:48 +03:00
default_layout_tools = ft . Row (
2022-11-19 21:10:13 +03:00
alignment = ' start ' ,
wrap = True ,
2022-11-21 00:11:50 +03:00
controls = [
] ,
2022-11-19 21:10:13 +03:00
)
2022-11-17 00:11:43 +03:00
2022-11-23 04:29:14 +03:00
# textual inversion tools
2022-11-19 21:10:13 +03:00
textual_inversion_layout_tools = ft . Row (
alignment = ' start ' ,
wrap = True ,
2022-11-21 00:11:50 +03:00
controls = [
] ,
2022-11-19 21:10:13 +03:00
)
2022-11-23 04:29:14 +03:00
# node editor tools
2022-11-19 21:10:13 +03:00
node_editor_layout_tools = ft . Row (
alignment = ' start ' ,
wrap = True ,
controls = [
] ,
)
current_layout_tools = ft . Column (
controls = [
2022-11-22 00:28:48 +03:00
default_layout_tools ,
2022-11-19 21:10:13 +03:00
] ,
)
toolbar = ft . Column (
2022-11-17 00:11:43 +03:00
controls = [
2022-11-21 00:11:50 +03:00
ft . Container ( content = universal_tools ) ,
ft . Container ( content = current_layout_tools ) ,
2022-11-17 00:11:43 +03:00
] ,
)
2022-11-19 21:10:13 +03:00
2022-11-23 04:29:14 +03:00
# layers panel #######################################################
2022-11-21 00:11:50 +03:00
def show_hide_layer ( e ) :
parent = e . control . data [ ' parent ' ]
if parent . data [ ' hidden ' ] :
parent . data [ ' hidden ' ] = False
parent . opacity = 1.0
else :
parent . data [ ' hidden ' ] = True
parent . opacity = 0.5
page . update ( )
def get_layers ( ) :
layers = [ ft . Divider ( height = 10 , opacity = 0 ) ]
count = 0
for i in range ( 10 ) :
count + = 1
layer_icon = ft . IconButton (
icon = ft . icons . HIGHLIGHT_ALT_OUTLINED ,
tooltip = ' show/hide ' ,
on_click = show_hide_layer ,
data = { ' parent ' : None } ,
)
layer_label = ft . Text ( value = ( " layer_ " + str ( count ) ) )
layer_button = ft . Row (
controls = [
layer_icon ,
layer_label ,
] ,
data = { ' hidden ' : False } ,
)
2022-11-23 04:29:14 +03:00
layer_icon . data . update ( { ' parent ' : layer_button } ) # <--see what i did there? :)
2022-11-21 00:11:50 +03:00
layers . append ( layer_button )
return layers
layer_list = get_layers ( )
layer_manager = ft . Container (
content = ft . Column (
controls = layer_list ,
) ,
bgcolor = ft . colors . WHITE10 ,
)
asset_manager = ft . Container (
content = ft . Column (
controls = [
ft . Divider ( height = 10 , opacity = 0 ) ,
2022-11-23 04:29:14 +03:00
ft . Text ( " Under Construction. " )
2022-11-21 00:11:50 +03:00
] ,
) ,
bgcolor = ft . colors . WHITE10 ,
)
layers = ft . Container (
width = 200 ,
content = ft . Tabs (
selected_index = 0 ,
animation_duration = 300 ,
tabs = [
ft . Tab (
text = " Layers " ,
content = layer_manager ,
) ,
ft . Tab (
text = " Assets " ,
content = asset_manager ,
) ,
] ,
) ,
)
2022-11-23 04:29:14 +03:00
# canvas #############################################################
2022-11-17 00:11:43 +03:00
canvas = ft . Container (
content = ft . Stack (
[
2022-11-21 00:11:50 +03:00
ft . Image (
2022-11-17 00:11:43 +03:00
src = f " https://i.redd.it/qdxksbar05o31.jpg " ,
#width=300,
#height=300,
#fit="contain",
gapless_playback = True ,
expand = True ,
) ,
] ,
2022-11-21 00:11:50 +03:00
clip_behavior = None ,
) ,
alignment = ft . alignment . center ,
expand = True ,
)
2022-11-23 04:29:14 +03:00
# text editor ########################################################
2022-11-21 00:11:50 +03:00
text_editor = ft . Container (
2022-11-23 04:29:14 +03:00
content = ft . Text ( " Under Construction. " ) ,
2022-11-21 00:11:50 +03:00
expand = True ,
)
2022-11-23 04:29:14 +03:00
# top panel ##########################################################
2022-11-21 00:11:50 +03:00
top_panel = ft . Container (
content = ft . Tabs (
selected_index = 0 ,
animation_duration = 300 ,
tabs = [
ft . Tab (
text = ' Canvas ' ,
content = canvas ,
) ,
ft . Tab (
text = ' Text Editor ' ,
content = text_editor ,
) ,
] ,
2022-11-17 00:11:43 +03:00
) ,
2022-11-21 00:11:50 +03:00
expand = True ,
)
2022-11-23 04:29:14 +03:00
# bottom_panel #######################################################
2022-11-21 00:11:50 +03:00
video_editor_window = ft . Container ( bgcolor = ft . colors . BLACK12 , height = 250 )
2022-11-22 00:28:48 +03:00
messages_window = ft . Container ( bgcolor = ft . colors . BLACK12 , height = 250 )
2022-11-21 00:11:50 +03:00
bottom_panel = ft . Row (
height = 150 ,
controls = [
ft . Tabs (
selected_index = 0 ,
animation_duration = 300 ,
tabs = [
ft . Tab (
2022-11-22 00:28:48 +03:00
text = " Messages " ,
content = messages_window ,
2022-11-21 00:11:50 +03:00
) ,
ft . Tab (
2022-11-22 00:28:48 +03:00
text = " Video Editor " ,
content = video_editor_window ,
2022-11-21 00:11:50 +03:00
) ,
] ,
) ,
] ,
)
2022-11-23 04:29:14 +03:00
# center panel #######################################################
2022-11-21 00:11:50 +03:00
center_panel = ft . Container (
content = ft . Column (
controls = [
top_panel ,
bottom_panel ,
] ,
) ,
expand = True ,
2022-11-17 00:11:43 +03:00
)
2022-11-23 04:29:14 +03:00
# property panel #####################################################
# canvas layout properties
2022-11-17 00:11:43 +03:00
model_menu = ft . Dropdown (
label = " Custom Models " ,
options = [
ft . dropdown . Option ( " Stable Diffusion 1.5 " ) ,
ft . dropdown . Option ( " Waifu Diffusion 1.3 " ) ,
ft . dropdown . Option ( " MM-27 Merged Pruned " ) ,
] ,
height = 70 ,
expand = 1 ,
2022-11-23 04:29:14 +03:00
content_padding = 10 ,
2022-11-17 00:11:43 +03:00
value = " Stable Diffusion 1.5 " ,
tooltip = " Custom models located in your `models/custom` folder including the default stable diffusion model. " ,
)
sampling_menu = ft . Dropdown (
label = " Sampling method " ,
options = [ #["k_lms", "k_euler", "k_euler_a", "k_dpm_2", "k_dpm_2_a", "k_heun", "PLMS", "DDIM"]
ft . dropdown . Option ( " k_lms " ) ,
ft . dropdown . Option ( " k_euler " ) ,
ft . dropdown . Option ( " k_euler_a " ) ,
ft . dropdown . Option ( " k_dpm_2 " ) ,
ft . dropdown . Option ( " k_dpm_2_a " ) ,
ft . dropdown . Option ( " k_heun " ) ,
ft . dropdown . Option ( " PLMS " ) ,
ft . dropdown . Option ( " DDIM " ) ,
] ,
height = 70 ,
expand = 1 ,
2022-11-23 04:29:14 +03:00
content_padding = 10 ,
2022-11-17 00:11:43 +03:00
value = " k_lms " ,
tooltip = " Sampling method or scheduler to use, different sampling method "
" or schedulers behave differently giving better or worst performance in more or less steps. "
" Try to find the best one for your needs and hardware. " ,
)
2022-11-22 00:28:48 +03:00
default_layout_properties = ft . Container (
2022-11-17 00:11:43 +03:00
content = ft . Column (
controls = [
ft . Row (
controls = [
model_menu ,
] ,
spacing = 4 ,
alignment = ' spaceAround ' ,
) ,
ft . Row (
controls = [
sampling_menu ,
] ,
spacing = 4 ,
alignment = ' spaceAround ' ,
) ,
ft . Row (
controls = [
2022-11-23 04:29:14 +03:00
ft . TextField ( label = " Width " , value = 512 , height = 50 , expand = 1 , content_padding = 10 , suffix_text = " W " , text_align = ' center ' , tooltip = " Widgth in pixels. " , keyboard_type = " number " ) ,
ft . TextField ( label = " Height " , value = 512 , height = 50 , expand = 1 , content_padding = 10 , suffix_text = " H " , text_align = ' center ' , tooltip = " Height in pixels. " , keyboard_type = " number " ) ,
2022-11-22 00:28:48 +03:00
] ,
spacing = 4 ,
alignment = ' spaceAround ' ,
) ,
ft . Row (
controls = [
2022-11-23 04:29:14 +03:00
ft . TextField ( label = " CFG " , value = 7.5 , height = 50 , expand = 1 , content_padding = 10 , text_align = ' center ' , #suffix_text="CFG",
2022-11-17 00:11:43 +03:00
tooltip = " Classifier Free Guidance Scale. " , keyboard_type = " number " ) ,
2022-11-23 04:29:14 +03:00
ft . TextField ( label = " Sampling Steps " , value = 30 , height = 50 , expand = 1 , content_padding = 10 , text_align = ' center ' , tooltip = " Sampling steps. " , keyboard_type = " number " ) ,
2022-11-17 00:11:43 +03:00
] ,
spacing = 4 ,
alignment = ' spaceAround ' ,
) ,
ft . Row (
controls = [
2022-11-22 00:28:48 +03:00
ft . TextField (
label = " Seed " ,
hint_text = " blank=random seed " ,
2022-11-23 04:29:14 +03:00
height = 50 ,
2022-11-22 00:28:48 +03:00
expand = 1 ,
2022-11-23 04:29:14 +03:00
content_padding = 10 ,
2022-11-22 00:28:48 +03:00
text_align = ' start ' ,
#suffix_text = "seed",
tooltip = " Seed used for the generation, leave empty or use -1 for a random seed. You can also use word as seeds. " ,
keyboard_type = " number "
2022-11-17 00:11:43 +03:00
) ,
] ,
spacing = 4 ,
alignment = ' spaceAround ' ,
) ,
ft . Draggable ( content = ft . Divider ( height = 10 , color = " gray " ) ) ,
2022-11-19 21:10:13 +03:00
# ft.Switch(label="Stable Horde", value=False, disabled=True, tooltip="Option disabled for now."),
# ft.Draggable(content=ft.Divider(height=10, color="gray")),
# ft.Switch(label="Batch Options", value=False, disabled=True, tooltip="Option disabled for now."),
# ft.Draggable(content=ft.Divider(height=10, color="gray")),
# ft.Switch(label="Upscaling", value=False, disabled=True, tooltip="Option disabled for now."),
# ft.Draggable(content=ft.Divider(height=10, color="gray")),
# ft.Switch(label="Preview Image Settings", value=False, disabled=True, tooltip="Option disabled for now."),
# ft.Draggable(content=ft.Divider(height=10, color="gray")),
]
) ,
expand = True
)
2022-11-23 04:29:14 +03:00
# textual inversion layout properties
2022-11-19 21:10:13 +03:00
clip_model_menu_label = ft . Text ( value = ' Clip Models ' , tooltip = " Select Clip model(s) to use. " )
clip_model_menu = ft . PopupMenuButton (
items = [
ft . PopupMenuItem ( text = " Vit-L/14 " , checked = False , data = ' Vit-L/14 ' , on_click = None ) ,
ft . PopupMenuItem ( text = " Vit-H-14 " , checked = False , data = ' Vit-H-14 ' , on_click = None ) ,
ft . PopupMenuItem ( text = " Vit-g-14 " , checked = False , data = ' Vit-g-14 ' , on_click = None ) ,
] ,
)
other_model_menu_label = ft . Text ( value = ' Other Models ' , tooltip = " For DiscoDiffusion and JAX enable all the same models here as you intend to use when generating your images. " )
other_model_menu = ft . PopupMenuButton (
items = [
ft . PopupMenuItem ( text = " VitL14_336px " , checked = False , data = ' VitL14_336px ' , on_click = None ) ,
ft . PopupMenuItem ( text = " VitB16 " , checked = False , data = ' VitB16 ' , on_click = None ) ,
ft . PopupMenuItem ( text = " VitB32 " , checked = False , data = ' VitB32 ' , on_click = None ) ,
ft . PopupMenuItem ( text = " RN50 " , checked = False , data = ' RN50 ' , on_click = None ) ,
ft . PopupMenuItem ( text = " RN50x4 " , checked = False , data = ' RN50x4 ' , on_click = None ) ,
ft . PopupMenuItem ( text = " RN50x16 " , checked = False , data = ' RN50x16 ' , on_click = None ) ,
ft . PopupMenuItem ( text = " RN50x64 " , checked = False , data = ' RN50x64 ' , on_click = None ) ,
ft . PopupMenuItem ( text = " RN101 " , checked = False , data = ' RN101 ' , on_click = None ) ,
] ,
)
def get_textual_inversion_settings ( ) :
settings = {
' selected_models ' : [ ] ,
' selected_images ' : [ ] ,
' results ' : [ ] ,
}
return settings
def get_textual_inversion_grid_row ( row_name ) :
row_items = [ ]
row_items . append ( ft . Text ( value = row_name ) )
2022-11-21 00:11:50 +03:00
row_items . append ( ft . Text ( value = webui_flet_utils . get_textual_inversion_row_value ( row_name ) ) )
2022-11-19 21:10:13 +03:00
return row_items
def get_textual_inversion_results_grid ( ) :
grid_rows = [ ]
2022-11-21 00:11:50 +03:00
for item in webui_flet_utils . textual_inversion_grid_row_list :
2022-11-19 21:10:13 +03:00
grid_rows . append (
ft . Row (
controls = get_textual_inversion_grid_row ( item ) ,
height = 50 ,
)
)
return ft . Column ( controls = grid_rows )
def get_textual_inversion_results ( e ) :
e . control . data = get_textual_inversion_settings ( )
2022-11-21 00:11:50 +03:00
webui_flet_utils . run_textual_inversion ( e . control . data )
2022-11-19 21:10:13 +03:00
textual_inversion_results . content = get_textual_inversion_results_grid ( )
page . update ( )
run_textual_inversion_button = ft . ElevatedButton ( " Get Text from Image(s) " , on_click = get_textual_inversion_results , data = { } )
textual_inversion_results = ft . Container ( content = None )
textual_inversion_layout_properties = ft . Container (
content = ft . Column (
controls = [
ft . Row (
controls = [
clip_model_menu_label ,
clip_model_menu ,
] ,
spacing = 4 ,
alignment = ' spaceAround ' ,
) ,
ft . Row (
controls = [
other_model_menu_label ,
other_model_menu ,
] ,
spacing = 4 ,
alignment = ' spaceAround ' ,
) ,
ft . Row (
controls = [
run_textual_inversion_button ,
] ,
alignment = ' spaceAround ' ,
) ,
2022-11-17 00:11:43 +03:00
ft . Draggable ( content = ft . Divider ( height = 10 , color = " gray " ) ) ,
2022-11-19 21:10:13 +03:00
ft . Row (
controls = [
textual_inversion_results ,
] ,
wrap = True ,
)
]
) ,
expand = True
)
2022-11-23 04:29:14 +03:00
# node editor layout properties
2022-11-19 21:10:13 +03:00
node_editor_layout_properties = ft . Container (
content = ft . Column (
controls = [
2022-11-17 00:11:43 +03:00
]
) ,
expand = True
)
2022-11-23 04:29:14 +03:00
# property panel
2022-11-21 00:11:50 +03:00
property_panel = ft . Container (
bgcolor = ft . colors . WHITE10 ,
content = ft . Column (
controls = [
ft . Divider ( height = 10 , opacity = 0 ) ,
2022-11-22 00:28:48 +03:00
default_layout_properties ,
2022-11-21 00:11:50 +03:00
] ,
) ,
2022-11-17 00:11:43 +03:00
)
2022-11-21 00:11:50 +03:00
2022-11-23 04:29:14 +03:00
# advanced panel
2022-11-21 00:11:50 +03:00
advanced_panel = ft . Container (
bgcolor = ft . colors . WHITE10 ,
content = ft . Column (
controls = [
ft . Divider ( height = 10 , opacity = 0 ) ,
2022-11-23 04:29:14 +03:00
ft . Text ( " Under Construction. " ) ,
2022-11-21 00:11:50 +03:00
] ,
) ,
2022-11-17 00:11:43 +03:00
)
2022-11-21 00:11:50 +03:00
right_panel = ft . Container (
content = ft . Tabs (
selected_index = 0 ,
animation_duration = 300 ,
tabs = [
2022-11-19 21:10:13 +03:00
ft . Tab (
2022-11-21 00:11:50 +03:00
text = ' Properties ' ,
content = property_panel ,
2022-11-19 21:10:13 +03:00
) ,
ft . Tab (
2022-11-21 00:11:50 +03:00
text = ' Advanced ' ,
content = advanced_panel ,
2022-11-19 21:10:13 +03:00
) ,
2022-11-21 00:11:50 +03:00
] ,
) ,
2022-11-22 00:28:48 +03:00
width = 250 ,
2022-11-21 00:11:50 +03:00
)
2022-11-23 04:29:14 +03:00
# workspace ##########################################################
2022-11-21 00:11:50 +03:00
workspace = ft . Row (
controls = [
toolbar ,
ft . VerticalDivider ( width = 2 , color = " gray " , opacity = 0 ) ,
layers ,
ft . VerticalDivider ( width = 2 , color = " gray " , opacity = 0 ) ,
center_panel ,
ft . VerticalDivider ( width = 2 , color = " gray " , opacity = 0 ) ,
right_panel ,
2022-11-20 04:00:58 +03:00
] ,
2022-11-21 00:11:50 +03:00
expand = True ,
2022-11-17 00:11:43 +03:00
)
2022-11-23 04:29:14 +03:00
# make page ##########################################################
2022-11-19 21:10:13 +03:00
page . title = " Stable Diffusion Playground "
page . theme_mode = " dark "
2022-11-17 00:11:43 +03:00
page . appbar = ft . AppBar (
#leading=leading,
#leading_width=leading_width,
automatically_imply_leading = True ,
#elevation=5,
bgcolor = ft . colors . BLACK26 ,
actions = [ appbar ]
)
2022-11-21 00:11:50 +03:00
page . add ( workspace )
2022-11-17 00:11:43 +03:00
2022-11-19 21:10:13 +03:00
2022-11-23 04:29:14 +03:00
ft . app ( target = main , port = 8505 , view = ft . WEB_BROWSER )