Skip to content

Commit

Permalink
Added option to show the progress percent value during a generation a…
Browse files Browse the repository at this point in the history
…s part of the title on the tab on the browser. This should be useful for when doing a generation but you need to do something on another tab but still want to keep track of the progress. (#1711)
  • Loading branch information
ZeroCool940711 committed Dec 8, 2022
2 parents 42d6b5d + 3e87802 commit d3f9d05
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 28 deletions.
1 change: 1 addition & 0 deletions configs/webui/webui_streamlit.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ general:
grid_quality: 95
n_rows: -1
no_verify_input: False
show_percent_in_tab_title: True
no_half: False
use_float16: False
precision: "autocast"
Expand Down
5 changes: 5 additions & 0 deletions scripts/Settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,11 @@ def layout():

st.session_state["defaults"].general.no_verify_input = st.checkbox("Do not Verify Input", value=st.session_state['defaults'].general.no_verify_input,
help="Do not verify input to check if it's too long. Default: False")

st.session_state["defaults"].general.show_percent_in_tab_title = st.checkbox("Show Percent in tab title", value=st.session_state['defaults'].general.show_percent_in_tab_title,
help="Add the progress percent value to the page title on the tab on your browser. "
"This is useful in case you need to know how the generation is going while doign something else"
"in another tab on your browser. Default: True")

st.session_state["defaults"].daisi_app.running_on_daisi_io = st.checkbox("Running on Daisi.io?", value=st.session_state['defaults'].daisi_app.running_on_daisi_io,
help="Specify if we are running on app.Daisi.io . Default: False")
Expand Down
8 changes: 6 additions & 2 deletions scripts/img2img.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
generation_callback, process_images, KDiffusionSampler, \
custom_models_available, RealESRGAN_available, GFPGAN_available, \
LDSR_available, load_models, hc, seed_to_int, logger, \
resize_image, get_matched_noise, CFGMaskedDenoiser, ImageFilter
resize_image, get_matched_noise, CFGMaskedDenoiser, ImageFilter, set_page_title

# streamlit imports
from streamlit.runtime.scriptrunner import StopException
Expand Down Expand Up @@ -735,8 +735,12 @@ def layout():
#show a message when the generation is complete.
message.success('Render Complete: ' + info + '; Stats: ' + stats, icon="✅")

except (StopException, KeyError):
except (StopException,
#KeyError
):
logger.info(f"Received Streamlit StopException")
# reset the page title so the percent doesnt stay on it confusing the user.
set_page_title(f"Stable Diffusion Playground")

# 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.
Expand Down
2 changes: 2 additions & 0 deletions scripts/sd_utils/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -1692,6 +1692,8 @@ def generation_callback(img, i=0):
if "progress_bar" in st.session_state:
try:
st.session_state["progress_bar"].progress(percent if percent < 100 else 100)
if st.session_state["defaults"].general.show_percent_in_tab_title:
set_page_title(f"({percent if percent < 100 else 100}%) Stable Diffusion Playground")
except UnboundLocalError as e:
#logger.error(e)
pass
Expand Down
55 changes: 30 additions & 25 deletions scripts/txt2img.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
save_sample, generation_callback, process_images, \
KDiffusionSampler, \
custom_models_available, RealESRGAN_available, GFPGAN_available, \
LDSR_available, load_models, hc, seed_to_int, logger
LDSR_available, load_models, hc, seed_to_int, logger, set_page_title

# streamlit imports
from streamlit.runtime.scriptrunner import StopException
Expand Down Expand Up @@ -670,30 +670,35 @@ def layout():

#print(st.session_state['use_RealESRGAN'])
#print(st.session_state['use_LDSR'])
#try:
#

output_images, seeds, info, stats = txt2img(prompt, st.session_state.sampling_steps, sampler_name, st.session_state["batch_count"], st.session_state["batch_size"],
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['GFPGAN_model'],
use_RealESRGAN=st.session_state["use_RealESRGAN"], RealESRGAN_model=st.session_state["RealESRGAN_model"],
use_LDSR=st.session_state["use_LDSR"], LDSR_model=st.session_state["LDSR_model"],
variant_amount=variant_amount, variant_seed=variant_seed, write_info_files=write_info_files,
use_stable_horde=use_stable_horde, stable_horde_key=stable_horde_key)

message.success('Render Complete: ' + info + '; Stats: ' + stats, icon="✅")

with gallery_tab:
logger.info(seeds)
st.session_state["gallery"].text = ""
sdGallery(output_images)


#except (StopException, KeyError):
#print(f"Received Streamlit StopException")
try:


# 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)
output_images, seeds, info, stats = txt2img(prompt, st.session_state.sampling_steps, sampler_name, st.session_state["batch_count"], st.session_state["batch_size"],
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['GFPGAN_model'],
use_RealESRGAN=st.session_state["use_RealESRGAN"], RealESRGAN_model=st.session_state["RealESRGAN_model"],
use_LDSR=st.session_state["use_LDSR"], LDSR_model=st.session_state["LDSR_model"],
variant_amount=variant_amount, variant_seed=variant_seed, write_info_files=write_info_files,
use_stable_horde=use_stable_horde, stable_horde_key=stable_horde_key)

message.success('Render Complete: ' + info + '; Stats: ' + stats, icon="✅")

with gallery_tab:
logger.info(seeds)
st.session_state["gallery"].text = ""
sdGallery(output_images)


except (StopException,
#KeyError
):
print(f"Received Streamlit StopException")

# reset the page title so the percent doesnt stay on it confusing the user.
set_page_title(f"Stable Diffusion Playground")

# 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)


8 changes: 7 additions & 1 deletion scripts/txt2vid.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
from sd_utils import st, MemUsageMonitor, server_state, no_rerun, torch_gc, \
custom_models_available, RealESRGAN_available, GFPGAN_available, \
LDSR_available, hc, seed_to_int, logger, slerp, optimize_update_preview_frequency, \
load_learned_embed_in_clip, load_GFPGAN, RealESRGANModel
load_learned_embed_in_clip, load_GFPGAN, RealESRGANModel, set_page_title


# streamlit imports
Expand Down Expand Up @@ -1082,6 +1082,9 @@ def diffuse(

if "progress_bar" in st.session_state:
st.session_state["progress_bar"].progress(total_percent if total_percent < 100 else 100)

if st.session_state["defaults"].general.show_percent_in_tab_title:
set_page_title(f"({percent if percent < 100 else 100}%) Stable Diffusion Playground")

except KeyError:
raise StopException
Expand Down Expand Up @@ -1593,6 +1596,9 @@ def txt2vid(
video_path = save_video_to_disk(frames, seeds, sanitized_prompt, save_video=save_video, outdir=outdir)

except StopException:
# reset the page title so the percent doesnt stay on it confusing the user.
set_page_title(f"Stable Diffusion Playground")

if save_video_on_stop:
logger.info("Streamlit Stop Exception Received. Saving video")
video_path = save_video_to_disk(frames, seeds, sanitized_prompt, save_video=save_video, outdir=outdir)
Expand Down

0 comments on commit d3f9d05

Please sign in to comment.