diff --git a/frontend/css/streamlit.main.css b/frontend/css/streamlit.main.css index 37f8000..a11d21d 100644 --- a/frontend/css/streamlit.main.css +++ b/frontend/css/streamlit.main.css @@ -92,4 +92,20 @@ button[kind="header"] { /*********************************************************** * Additional CSS for other elements -************************************************************/ \ No newline at end of file +************************************************************/ +button[data-baseweb="tab"] { + font-size: 20px; +} + +@media (min-width: 1200px){ +h1 { + font-size: 1.75rem; +} +} +#tabs-1-tabpanel-0 > div:nth-child(1) > div > div.stTabs.css-0.exp6ofz0 { + width: 50rem; + align-self: center; +} +div.gallery:hover { + border: 1px solid #777; +} \ No newline at end of file diff --git a/scripts/home.py b/scripts/home.py index 7f3ce7e..2103dd8 100644 --- a/scripts/home.py +++ b/scripts/home.py @@ -1,5 +1,18 @@ -from webui_streamlit import st, defaults +# base webui import and utils. +from webui_streamlit import st from sd_utils import * + +# streamlit imports + + +#other imports + +# Temp imports + + +# end of imports +#--------------------------------------------------------------------------------------------------------------- + import os from PIL import Image @@ -30,15 +43,17 @@ def getLatestGeneratedImagesFromPath(): files.append(os.path.join(r, file)) #sort the files by date files.sort(key=os.path.getmtime) + #reverse the list so the latest images are first for f in files: img = Image.open(f) files[files.index(f)] = img + #get the latest 10 files #get all the files with the .png or .jpg extension #sort files by date #get the latest 10 files - latestFiles = files[-10:] + latestFiles = files #reverse the list latestFiles.reverse() return latestFiles @@ -98,41 +113,109 @@ def layout(): # create a tab for the gallery #st.markdown("

Gallery

", unsafe_allow_html=True) #st.markdown("

Gallery

", unsafe_allow_html=True) - history_tab, discover_tabs, settings_tab = st.tabs(["History","Discover","Settings"]) - with discover_tabs: - st.markdown("

Soon :)

", unsafe_allow_html=True) - with settings_tab: - st.markdown("

Soon :)

", unsafe_allow_html=True) + + history_tab, discover_tabs = st.tabs(["History","Discover"]) + + latestImages = getLatestGeneratedImagesFromPath() + st.session_state['latestImages'] = latestImages + with history_tab: + ##--------------------------------------------------------- + ## image slideshow test + ## Number of entries per screen + #slideshow_N = 9 + #slideshow_page_number = 0 + #slideshow_last_page = len(latestImages) // slideshow_N + + ## Add a next button and a previous button + + #slideshow_prev, slideshow_image_col , slideshow_next = st.columns([1, 10, 1]) + + #with slideshow_image_col: + #slideshow_image = st.empty() + + #slideshow_image.image(st.session_state['latestImages'][0]) + + #current_image = 0 + + #if slideshow_next.button("Next", key=1): + ##print (current_image+1) + #current_image = current_image+1 + #slideshow_image.image(st.session_state['latestImages'][current_image+1]) + #if slideshow_prev.button("Previous", key=0): + ##print ([current_image-1]) + #current_image = current_image-1 + #slideshow_image.image(st.session_state['latestImages'][current_image - 1]) + + + #--------------------------------------------------------- + placeholder = st.empty() - - - - latestImages = getLatestGeneratedImagesFromPath() - st.session_state['latestImages'] = latestImages - + + + # image gallery + # Number of entries per screen + gallery_N = 9 + gallery_page_number = 0 + #gallery_last_page = len(latestImages) // gallery_N + + # Add a next button and a previous button + + #gallery_prev, gallery_pagination , gallery_next = st.columns([1, 10, 1]) + + # the pagination doesnt work for now so its better to disable the buttons. + + #if gallery_next.button("Next", key=3): + + #if gallery_page_number + 1 > gallery_last_page: + #gallery_page_number = 0 + #else: + #gallery_page_number += 1 + + #if gallery_prev.button("Previous", key=2): + + #if gallery_page_number - 1 < 0: + #gallery_page_number = gallery_last_page + #else: + #gallery_page_number -= 1 + + # Get start and end indices of the next page of the dataframe + gallery_start_idx = gallery_page_number * gallery_N + gallery_end_idx = (1 + gallery_page_number) * gallery_N + + #--------------------------------------------------------- + #populate the 3 images per column with placeholder.container(): col1, col2, col3 = st.columns(3) col1_cont = st.container() col2_cont = st.container() col3_cont = st.container() + + #print (len(st.session_state['latestImages'][gallery_start_idx:gallery_end_idx])) + with col1_cont: with col1: - st.image(st.session_state['latestImages'][0]) - st.image(st.session_state['latestImages'][3]) - st.image(st.session_state['latestImages'][6]) + st.image(st.session_state['latestImages'][gallery_start_idx:gallery_end_idx][0]) + st.image(st.session_state['latestImages'][gallery_start_idx:gallery_end_idx][3]) + st.image(st.session_state['latestImages'][gallery_start_idx:gallery_end_idx][6]) with col2_cont: with col2: - st.image(st.session_state['latestImages'][1]) - st.image(st.session_state['latestImages'][4]) - st.image(st.session_state['latestImages'][7]) + st.image(st.session_state['latestImages'][gallery_start_idx:gallery_end_idx][1]) + st.image(st.session_state['latestImages'][gallery_start_idx:gallery_end_idx][4]) + st.image(st.session_state['latestImages'][gallery_start_idx:gallery_end_idx][7]) with col3_cont: with col3: - st.image(st.session_state['latestImages'][2]) - st.image(st.session_state['latestImages'][5]) - st.image(st.session_state['latestImages'][8]) - st.session_state['historyTab'] = [history_tab,col1,col2,col3,placeholder,col1_cont,col2_cont,col3_cont] + st.image(st.session_state['latestImages'][gallery_start_idx:gallery_end_idx][2]) + st.image(st.session_state['latestImages'][gallery_start_idx:gallery_end_idx][5]) + st.image(st.session_state['latestImages'][gallery_start_idx:gallery_end_idx][8]) + + + st.session_state['historyTab'] = [history_tab,col1,col2,col3,placeholder,col1_cont,col2_cont,col3_cont] + + with discover_tabs: + st.markdown("

Soon :)

", unsafe_allow_html=True) + #display the images #add a button to the gallery #st.markdown("

Try it out

", unsafe_allow_html=True) @@ -140,3 +223,4 @@ def layout(): #if st.button("Try it out"): #if the button is clicked, go to the gallery #st.experimental_rerun() + \ No newline at end of file diff --git a/scripts/txt2img.py b/scripts/txt2img.py index 0aa9162..6fac83f 100644 --- a/scripts/txt2img.py +++ b/scripts/txt2img.py @@ -30,11 +30,11 @@ except: pass class plugin_info(): - plugname = "txt2img" - description = "Text to Image" - isTab = True - displayPriority = 1 - + plugname = "txt2img" + description = "Text to Image" + isTab = True + displayPriority = 1 + if os.path.exists(os.path.join(st.session_state['defaults'].general.GFPGAN_dir, "experiments", "pretrained_models", "GFPGANv1.3.pth")): GFPGAN_available = True @@ -93,14 +93,14 @@ def txt2img(prompt: str, ddim_steps: int, sampler_name: str, realesrgan_model_na def sample(init_data, x, conditioning, unconditional_conditioning, sampler_name): samples_ddim, _ = sampler.sample(S=ddim_steps, conditioning=conditioning, batch_size=int(x.shape[0]), shape=x[0].shape, verbose=False, unconditional_guidance_scale=cfg_scale, - unconditional_conditioning=unconditional_conditioning, eta=ddim_eta, x_T=x, img_callback=generation_callback, - log_every_t=int(st.session_state.update_preview_frequency)) + unconditional_conditioning=unconditional_conditioning, eta=ddim_eta, x_T=x, img_callback=generation_callback, + log_every_t=int(st.session_state.update_preview_frequency)) return samples_ddim #try: output_images, seed, info, stats = process_images( - outpath=outpath, + outpath=outpath, func_init=init, func_sample=sample, prompt=prompt, @@ -126,7 +126,7 @@ def txt2img(prompt: str, ddim_steps: int, sampler_name: str, realesrgan_model_na jpg_sample=save_as_jpg, variant_amount=variant_amount, variant_seed=variant_seed, - ) + ) del sampler @@ -143,7 +143,7 @@ def layout(): st.session_state["generation_mode"] = "txt2img" input_col1, generate_col1 = st.columns([10,1]) - + with input_col1: #prompt = st.text_area("Input Text","") prompt = st.text_input("Input Text","", placeholder="A corgi wearing a top hat as an oil painting.") @@ -179,12 +179,12 @@ def layout(): with st.expander("Preview Settings"): st.session_state["update_preview"] = st.checkbox("Update Image Preview", value=st.session_state['defaults'].txt2img.update_preview, - help="If enabled the image preview will be updated during the generation instead of at the end. \ + help="If enabled the image preview will be updated during the generation instead of at the end. \ You can use the Update Preview \Frequency option bellow to customize how frequent it's updated. \ By default this is enabled and the frequency is set to 1 step.") - + st.session_state["update_preview_frequency"] = st.text_input("Update Image Preview Frequency", value=st.session_state['defaults'].txt2img.update_preview_frequency, - help="Frequency in steps at which the the preview image is updated. By default the frequency \ + help="Frequency in steps at which the the preview image is updated. By default the frequency \ is set to 1 step.") with col2: @@ -206,20 +206,20 @@ def layout(): st.session_state["progress_bar"] = st.empty() message = st.empty() - + with col3: # If we have custom models available on the "models/custom" #folder then we show a menu to select which model we want to use, otherwise we use the main model for SD - if st.session_state["CustomModel_available"]: - st.session_state["custom_model"] = st.selectbox("Custom Model:", st.session_state["custom_models"], - index=st.session_state["custom_models"].index(st.session_state['defaults'].general.default_model), - help="Select the model you want to use. This option is only available if you have custom models \ + if st.session_state.CustomModel_available: + st.session_state.custom_model = st.selectbox("Custom Model:", st.session_state.custom_models, + index=st.session_state["custom_models"].index(st.session_state['defaults'].general.default_model), + help="Select the model you want to use. This option is only available if you have custom models \ on your 'models/custom' folder. The model name that will be shown here is the same as the name\ the file for the model has on said folder, it is recommended to give the .ckpt file a name that \ will make it easier for you to distinguish it from other models. Default: Stable Diffusion v1.4") - + st.session_state.sampling_steps = st.slider("Sampling Steps", value=st.session_state['defaults'].txt2img.sampling_steps, min_value=1, max_value=250) - + sampler_name_list = ["k_lms", "k_euler", "k_euler_a", "k_dpm_2", "k_dpm_2_a", "k_heun", "PLMS", "DDIM"] sampler_name = st.selectbox("Sampling method", sampler_name_list, index=sampler_name_list.index(st.session_state['defaults'].txt2img.default_sampler), help="Sampling method to use. Default: k_euler") @@ -238,7 +238,7 @@ def layout(): save_individual_images = st.checkbox("Save individual images.", value=True, help="Save each image generated before any filter or enhancement is applied.") save_grid = st.checkbox("Save grid",value=True, help="Save a grid with all the images generated into a single image.") group_by_prompt = st.checkbox("Group results by prompt", value=True, - help="Saves all the images with the same prompt into the same folder. When using a prompt matrix each prompt combination will have its own folder.") + help="Saves all the images with the same prompt into the same folder. When using a prompt matrix each prompt combination will have its own folder.") write_info_files = st.checkbox("Write Info file", value=True, help="Save a file next to the image with informartion about the generation.") save_as_jpg = st.checkbox("Save samples as jpg", value=False, help="Saves the images as jpg instead of png.") @@ -247,10 +247,10 @@ def layout(): This greatly improve the quality and consistency of faces but uses extra VRAM. Disable if you need the extra VRAM.") else: st.session_state["use_GFPGAN"] = False - + if st.session_state["RealESRGAN_available"]: st.session_state["use_RealESRGAN"] = st.checkbox("Use RealESRGAN", value=st.session_state['defaults'].txt2img.use_RealESRGAN, - help="Uses the RealESRGAN model to upscale the images after the generation.\ + help="Uses the RealESRGAN model to upscale the images after the generation.\ This greatly improve the quality and lets you have high resolution images but uses extra VRAM. Disable if you need the extra VRAM.") st.session_state["RealESRGAN_model"] = st.selectbox("RealESRGAN model", ["RealESRGAN_x4plus", "RealESRGAN_x4plus_anime_6B"], index=0) else: @@ -265,18 +265,18 @@ def layout(): #print("Loading models") # load the models when we hit the generate button for the first time, it wont be loaded after that so dont worry. load_models(False, st.session_state["use_GFPGAN"], st.session_state["use_RealESRGAN"], st.session_state["RealESRGAN_model"], st.session_state["CustomModel_available"], - st.session_state["custom_model"]) + st.session_state["custom_model"]) try: output_images, seeds, info, stats = txt2img(prompt, st.session_state.sampling_steps, sampler_name, st.session_state["RealESRGAN_model"], batch_count, batch_size, - cfg_scale, seed, height, width, separate_prompts, normalize_prompt_weights, save_individual_images, + cfg_scale, seed, height, width, separate_prompts, normalize_prompt_weights, save_individual_images, save_grid, group_by_prompt, save_as_jpg, st.session_state["use_GFPGAN"], st.session_state["use_RealESRGAN"], st.session_state["RealESRGAN_model"], - fp=st.session_state.defaults.general.fp, variant_amount=variant_amount, variant_seed=variant_seed, write_info_files=write_info_files) - + fp=st.session_state.defaults.general.fp, variant_amount=variant_amount, variant_seed=variant_seed, write_info_files=write_info_files) + message.success('Render Complete: ' + info + '; Stats: ' + stats, icon="✅") - + history_tab,col1,col2,col3,PlaceHolder,col1_cont,col2_cont,col3_cont = st.session_state['historyTab'] - + if 'latestImages' in st.session_state: for i in output_images: #push the new image to the list of latest images and remove the oldest one @@ -307,61 +307,62 @@ def layout(): st.image(st.session_state['latestImages'][8]) historyGallery = st.empty() - # check if output_images length is the same as seeds length - with gallery_tab: - st.markdown(createHTMLGallery(output_images,seeds), unsafe_allow_html=True) - + # check if output_images length is the same as seeds length + with gallery_tab: + st.markdown(createHTMLGallery(output_images,seeds), unsafe_allow_html=True) + + + st.session_state['historyTab'] = [history_tab,col1,col2,col3,PlaceHolder,col1_cont,col2_cont,col3_cont] - st.session_state['historyTab'] = [history_tab,col1,col2,col3,PlaceHolder,col1_cont,col2_cont,col3_cont] except (StopException, KeyError): print(f"Received Streamlit StopException") - - # this will render all the images at the end of the generation but its better if its moved to a second tab inside col2 and shown as a gallery. - # use the current col2 first tab to show the preview_img and update it as its generated. - #preview_image.image(output_images) + + # this will render all the images at the end of the generation but its better if its moved to a second tab inside col2 and shown as a gallery. + # use the current col2 first tab to show the preview_img and update it as its generated. + #preview_image.image(output_images) #on import run init def createHTMLGallery(images,info): - html3 = """ + html3 = """ ' + return html3 \ No newline at end of file diff --git a/scripts/txt2vid.py b/scripts/txt2vid.py index 88f3201..0df27fc 100644 --- a/scripts/txt2vid.py +++ b/scripts/txt2vid.py @@ -481,7 +481,7 @@ def txt2vid( Took { round(time_diff, 2) }s total ({ round(time_diff/(max_frames),2) }s per image) Peak memory usage: { -(mem_max_used // -1_048_576) } MiB / { -(mem_total // -1_048_576) } MiB / { round(mem_max_used/mem_total*100, 3) }%''' - return im, seeds, info, stats + return video_path, seeds, info, stats #on import run init def createHTMLGallery(images,info): @@ -679,7 +679,7 @@ def layout(): #load_models(False, False, False, st.session_state["RealESRGAN_model"], CustomModel_available=st.session_state["CustomModel_available"], custom_model=custom_model) # run video generation - image, seed, info, stats = txt2vid(prompts=prompt, gpu=st.session_state["defaults"].general.gpu, + video, seed, info, stats = txt2vid(prompts=prompt, gpu=st.session_state["defaults"].general.gpu, num_steps=st.session_state.sampling_steps, max_frames=int(st.session_state.max_frames), num_inference_steps=st.session_state.num_inference_steps, cfg_scale=cfg_scale,do_loop=st.session_state["do_loop"], @@ -690,12 +690,49 @@ def layout(): #message.success('Done!', icon="✅") message.success('Render Complete: ' + info + '; Stats: ' + stats, icon="✅") + + history_tab,col1,col2,col3,PlaceHolder,col1_cont,col2_cont,col3_cont = st.session_state['historyTab'] + + #if 'latestVideos' in st.session_state: + #for i in video: + ##push the new image to the list of latest images and remove the oldest one + ##remove the last index from the list\ + #st.session_state['latestVideos'].pop() + ##add the new image to the start of the list + #st.session_state['latestVideos'].insert(0, i) + #PlaceHolder.empty() + + #with PlaceHolder.container(): + #col1, col2, col3 = st.columns(3) + #col1_cont = st.container() + #col2_cont = st.container() + #col3_cont = st.container() + + #with col1_cont: + #with col1: + #st.image(st.session_state['latestVideos'][0]) + #st.image(st.session_state['latestVideos'][3]) + #st.image(st.session_state['latestVideos'][6]) + #with col2_cont: + #with col2: + #st.image(st.session_state['latestVideos'][1]) + #st.image(st.session_state['latestVideos'][4]) + #st.image(st.session_state['latestVideos'][7]) + #with col3_cont: + #with col3: + #st.image(st.session_state['latestVideos'][2]) + #st.image(st.session_state['latestVideos'][5]) + #st.image(st.session_state['latestVideos'][8]) + #historyGallery = st.empty() + + ## check if output_images length is the same as seeds length + #with gallery_tab: + #st.markdown(createHTMLGallery(video,seed), unsafe_allow_html=True) + + + #st.session_state['historyTab'] = [history_tab,col1,col2,col3,PlaceHolder,col1_cont,col2_cont,col3_cont] #except (StopException, KeyError): #print(f"Received Streamlit StopException") - # this will render all the images at the end of the generation but its better if its moved to a second tab inside col2 and shown as a gallery. - # use the current col2 first tab to show the preview_img and update it as its generated. - #preview_image.image(output_images) - diff --git a/scripts/webui_streamlit.py b/scripts/webui_streamlit.py index 1f8141f..5288545 100644 --- a/scripts/webui_streamlit.py +++ b/scripts/webui_streamlit.py @@ -105,8 +105,12 @@ def layout(): iconName=['dashboard','model_training' ,'cloud_download', 'settings'], default_choice=0) if tabs =='Stable Diffusion': - txt2img_tab, img2img_tab, txt2vid_tab, postprocessing_tab = st.tabs(["Text-to-Image Unified", "Image-to-Image Unified", - "Text-to-Video","Post-Processing"]) + home_tab, txt2img_tab, img2img_tab, txt2vid_tab, postprocessing_tab = st.tabs(["Home","Text-to-Image Unified", "Image-to-Image Unified", + "Text-to-Video","Post-Processing"]) + with home_tab: + from home import layout + layout() + with txt2img_tab: from txt2img import layout layout()