For now, working release.
Test- OK

Co-Authored-By: Edesak <20689154+Edesak@users.noreply.github.com>
pull/1/head
Dave 2023-04-03 20:26:26 +02:00
parent a280994ac1
commit d695ddb702
1 changed files with 22 additions and 25 deletions

View File

@ -2,34 +2,27 @@ import gradio as gr
from modules import script_callbacks
from modules import ui
from modules import shared
# from modules.txt2img import get_batch_size WIP
import threading
import time
import os
from modules.processing import StableDiffusionProcessing
github_link = "https://github.com/davehornik/sd-discordRPC"
github_link = "https://github.com/davehornik/sd-discord-rich_presence"
enable_dynamic_status = True
def start_rpc():
print('[Discord-RPC] Running Discord Rich Presence Extension by https://github.com/davehornik, version 1.0.0')
print(f'[Discord-RPC] Bug reporting -> {github_link}')
print('[Discord Rich Presence] Running Discord Rich Presence Extension, version 1.1.0')
print(f'[Discord Rich Presence] Bug reporting -> {github_link}')
# 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-RPC] Installing missing 'pypresence' module and its dependencies,")
print("[Discord-RPC] In case of module error after the installation, restart webui.")
run_pip("install pypresence", "pypresence")
if enable_dynamic_status:
print("[Discord-RPC] Remember that it uses multithreading, so there may occur cases when the whole program freezes")
print("[Discord-RPC] Remember that it uses multithreading, so there may occur cases when the whole program freezes")
print("[Discord-RPC] In such cases close the webui, go to the 'extensions' folder and remove the plugin")
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.")
checkpoint_info = shared.sd_model.sd_checkpoint_info
model_name = os.path.basename(checkpoint_info.filename)
@ -43,7 +36,7 @@ def start_rpc():
time_c = time.time()
rpc.update(
state="Waiting for the start" if enable_dynamic_status else "Dynamic Status - *WIP*",
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
@ -52,9 +45,8 @@ def start_rpc():
state_watcher.start()
if enable_dynamic_status:
print(
"[Discord-RPC] If everyhing is okey, it should be working already. Make sure u got Game Activity enabled in Discord.")
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):
reset_time = False
batch_size_r = False
@ -74,19 +66,25 @@ def state_watcher_thread(rpc):
batch_size_r = False
batch_size = 0
rpc.update(large_image="a1111", details=model_name,
state="Idle", start=time_c)
rpc.update(large_image="a1111",
details=model_name,
state="Idle",
start=time_c)
else:
if reset_time == True:
time_c = time.time()
reset_time = False
if batch_size_r == False:
batch_size = get_batch_size()
if batch_size != 0:
batch_size_r = True
rpc.update(large_image="a1111_gen", details=model_name,
state=f'Total batch of {shared.state.job_count * batch_size} image/s', start=time_c)
rpc.update(large_image="a1111_gen",
details=model_name,
state=f'Total batch of {shared.state.job_count * batch_size} image/s',
start=time_c)
time.sleep(2) # update once per two seconds
@ -103,5 +101,4 @@ def get_batch_size():
else:
return 0
script_callbacks.on_ui_tabs(on_ui_tabs)
script_callbacks.on_ui_tabs(on_ui_tabs)