Added percantage progress

Added percantage progress with small picture changes.
pull/5/head
Edesak 2023-04-09 19:37:39 +02:00
parent d9e2054e61
commit a862e51684
1 changed files with 67 additions and 13 deletions

View File

@ -1,6 +1,4 @@
import gradio as gr
from modules import script_callbacks
from modules import ui
from modules import shared
import threading
import time
@ -10,6 +8,7 @@ github_link = "https://github.com/davehornik/sd-discord-rich_presence"
enable_dynamic_status = True
def start_rpc():
print('[Discord Rich Presence] Running Discord Rich Presence Extension, version 1.1.0')
print(f'[Discord Rich Presence] Bug reporting -> {github_link}')
@ -17,9 +16,9 @@ def start_rpc():
# Check if the required packages are installed, and install them if necessary
from launch import is_installed, run_pip
if not is_installed("pypresence"):
print("[Discord Rich Presence] Installing missing 'pypresence' module and its dependencies,")
print("[Discord Rich Presence] In case of module error after the installation -> restart WebUI.")
run_pip("install pypresence", "pypresence")
print("[Discord Rich Presence] Installing missing 'pypresence' module and its dependencies,")
print("[Discord Rich Presence] In case of module error after the installation -> restart WebUI.")
run_pip("install pypresence", "pypresence")
else:
print("[Discord Rich Presence] 'pypresence' module is installed - skipping.")
@ -38,19 +37,49 @@ def start_rpc():
state="Waiting for the start" if enable_dynamic_status else "Dynamic Status - OFF",
details=model_name,
large_image="unknown" if enable_dynamic_status else "auto",
start=time_c
start=int(time_c)
)
state_watcher = threading.Thread(target=state_watcher_thread, args=(rpc,), daemon=True)
state_watcher = threading.Thread(target=state_watcher_thread, args=(rpc, time_c), daemon=True)
state_watcher.start()
if enable_dynamic_status:
print("[Discord Rich Presence] Make sure that Game Activity is enabled in Discord.")
print("[Discord Rich Presence] Should be running already if there's no error.")
def state_watcher_thread(rpc):
def state_watcher_thread(rpc, time_c):
reset_time = False
batch_size_r = False
batch_size = 0
status = True
total_progress = 0
image_to_show = "small_gen_00"
percent_show = 0
dict_images = {
0: "small_gen_00",
5: "small_gen_05",
10: "small_gen_10",
15: "small_gen_15",
20: "small_gen_20",
25: "small_gen_25",
30: "small_gen_30",
35: "small_gen_35",
40: "small_gen_40",
45: "small_gen_45",
50: "small_gen_50",
55: "small_gen_55",
60: "small_gen_60",
65: "small_gen_65",
70: "small_gen_70",
75: "small_gen_75",
80: "small_gen_80",
85: "small_gen_85",
90: "small_gen_90",
95: "small_gen_95",
100: "small_gen_100"
}
while True:
@ -62,7 +91,7 @@ def state_watcher_thread(rpc):
if shared.state.job_count == 0:
if reset_time == False:
time_c = time.time()
time_c = int(time.time())
reset_time = True
if batch_size_r == True:
@ -75,27 +104,51 @@ def state_watcher_thread(rpc):
start=time_c)
else:
if reset_time == True:
time_c = time.time()
time_c = int(time.time())
reset_time = False
if batch_size_r == False:
batch_size = get_batch_size()
if batch_size != 0:
batch_size_r = True
if shared.total_tqdm._tqdm is not None:
if status:
total_progress = shared.state.sampling_steps * shared.state.job_count
status = False
# This is really nasty line of code please don't look or i will cry :'( Edesak
progress = shared.total_tqdm._tqdm.n
percent_progress = progress / total_progress * 100
else:
percent_progress = 0
for image in dict_images:
if image >= int(percent_progress):
image_to_show = dict_images[image]
percent_show = image
break
rpc.update(large_image="a1111_gen",
small_image=image_to_show,
large_text="Generating",
small_text=f"{percent_show}%",
details=model_name,
state=f'Total batch of {shared.state.job_count * batch_size} image/s',
state=f'Generating {shared.state.job_count * batch_size} image/s',
start=time_c)
time.sleep(2) # update once per two seconds
def on_ui_tabs():
start_rpc()
return []
def get_batch_size():
def get_batch_size():
if shared.state.current_latent != None:
x = shared.state.current_latent.size()
x = x[0]
@ -103,4 +156,5 @@ def get_batch_size():
else:
return 0
script_callbacks.on_ui_tabs(on_ui_tabs)
script_callbacks.on_ui_tabs(on_ui_tabs)