This commit is contained in:
Divided by Zer0 2022-10-14 22:27:56 +02:00
parent fd51bab1ec
commit 616d586acf
3 changed files with 35 additions and 22 deletions

View File

@ -0,0 +1 @@
from logger, set_logger_verbosity, quiesce_logger

View File

@ -70,6 +70,7 @@ from typing import Dict
from io import BytesIO
import librosa
from decorest import backend, RestClient, GET, query, PUT, POST, DELETE, HEAD, OPTIONS
from . import logger
# Temp imports
#from basicsr.utils.registry import ARCH_REGISTRY
@ -2622,7 +2623,7 @@ def run_bridge(interval, api_key, horde_name, horde_url, priority_usernames, hor
loop_retry = 0
while True:
if loop_retry > 10 and current_id:
print(f"Exceeded retry count {loop_retry} for generation id {current_id}. Aborting generation!")
logger.info(f"Exceeded retry count {loop_retry} for generation id {current_id}. Aborting generation!")
current_id = None
current_payload = None
current_generation = None
@ -2635,6 +2636,7 @@ def run_bridge(interval, api_key, horde_name, horde_url, priority_usernames, hor
"priority_usernames": priority_usernames,
"nsfw": horde_nsfw,
"blacklist": horde_blacklist,
"models": ["stable_diffusion"],
}
headers = {"apikey": api_key}
if current_id:
@ -2643,28 +2645,28 @@ def run_bridge(interval, api_key, horde_name, horde_url, priority_usernames, hor
try:
pop_req = requests.post(horde_url + '/api/v2/generate/pop', json = gen_dict, headers = headers)
except requests.exceptions.ConnectionError:
print(f"Server {horde_url} unavailable during pop. Waiting 10 seconds...")
logger.warning(f"Server {horde_url} unavailable during pop. Waiting 10 seconds...")
time.sleep(10)
continue
except requests.exceptions.JSONDecodeError():
print(f"Server {horde_url} unavailable during pop. Waiting 10 seconds...")
logger.warning(f"Server {horde_url} unavailable during pop. Waiting 10 seconds...")
time.sleep(10)
continue
try:
pop = pop_req.json()
except json.decoder.JSONDecodeError:
print(f"Could not decode response from {horde_url} as json. Please inform its administrator!")
logger.warning(f"Could not decode response from {horde_url} as json. Please inform its administrator!")
time.sleep(interval)
continue
if pop == None:
print(f"Something has gone wrong with {horde_url}. Please inform its administrator!")
logger.warning(f"Something has gone wrong with {horde_url}. Please inform its administrator!")
time.sleep(interval)
continue
if not pop_req.ok:
message = pop['message']
print(f"During gen pop, server {horde_url} responded with status code {pop_req.status_code}: {pop['message']}. Waiting for 10 seconds...")
logger.warning(f"During gen pop, server {horde_url} responded with status code {pop_req.status_code}: {pop['message']}. Waiting for 10 seconds...")
if 'errors' in pop:
print(f"Detailed Request Errors: {pop['errors']}")
logger.debug(f"Detailed Request Errors: {pop['errors']}")
time.sleep(10)
continue
if not pop.get("id"):
@ -2673,14 +2675,14 @@ def run_bridge(interval, api_key, horde_name, horde_url, priority_usernames, hor
skipped_info = f" Skipped Info: {skipped_info}."
else:
skipped_info = ''
print(f"Server {horde_url} has no valid generations to do for us.{skipped_info}")
logger.info(f"Server {horde_url} has no valid generations to do for us.{skipped_info}")
time.sleep(interval)
continue
current_id = pop['id']
print(f"Request with id {current_id} picked up. Initiating work...")
logger.info(f"Request with id {current_id} picked up. Initiating work...")
current_payload = pop['payload']
if 'toggles' in current_payload and current_payload['toggles'] == None:
print(f"Received Bad payload: {pop}")
logger.error(f"Received Bad payload: {pop}")
current_id = None
current_payload = None
current_generation = None
@ -2688,7 +2690,7 @@ def run_bridge(interval, api_key, horde_name, horde_url, priority_usernames, hor
time.sleep(10)
continue
print (current_payload)
logger.debug(current_payload)
current_payload['toggles'] = current_payload.get('toggles', [1,4])
# In bridge-mode, matrix is prepared on the horde and split in multiple nodes
if 0 in current_payload['toggles']:
@ -2731,25 +2733,25 @@ def run_bridge(interval, api_key, horde_name, horde_url, priority_usernames, hor
try:
submit = submit_req.json()
except json.decoder.JSONDecodeError:
print(f"Something has gone wrong with {horde_url} during submit. Please inform its administrator! (Retry {loop_retry}/10)")
logger.error(f"Something has gone wrong with {horde_url} during submit. Please inform its administrator! (Retry {loop_retry}/10)")
time.sleep(interval)
continue
if submit_req.status_code == 404:
print(f"The generation we were working on got stale. Aborting!")
elif not submit_req.ok:
print(f"During gen submit, server {horde_url} responded with status code {submit_req.status_code}: {submit['message']}. Waiting for 10 seconds... (Retry {loop_retry}/10)")
logger.error(f"During gen submit, server {horde_url} responded with status code {submit_req.status_code}: {submit['message']}. Waiting for 10 seconds... (Retry {loop_retry}/10)")
if 'errors' in submit:
print(f"Detailed Request Errors: {submit['errors']}")
logger.debug(f"Detailed Request Errors: {submit['errors']}")
time.sleep(10)
continue
else:
print(f'Submitted generation with id {current_id} and contributed for {submit_req.json()["reward"]}')
logger.info(f'Submitted generation with id {current_id} and contributed for {submit_req.json()["reward"]}')
current_id = None
current_payload = None
current_generation = None
loop_retry = 0
except requests.exceptions.ConnectionError:
print(f"Server {horde_url} unavailable during submit. Waiting 10 seconds... (Retry {loop_retry}/10)")
logger.warning(f"Server {horde_url} unavailable during submit. Waiting 10 seconds... (Retry {loop_retry}/10)")
time.sleep(10)
continue
time.sleep(interval)

View File

@ -28,6 +28,7 @@ import streamlit_nested_layout
#streamlit components section
from st_on_hover_tabs import on_hover_tabs
from streamlit_server_state import server_state, server_state_lock
from . import logger, set_logger_verbosity, quiesce_logger
#other imports
@ -76,6 +77,7 @@ parser.add_argument('--horde_sfw', action='store_true', required=False, help="Se
parser.add_argument('--horde_blacklist', nargs='+', required=False, help="List the words that you want to blacklist.")
parser.add_argument('--horde_censorlist', nargs='+', required=False, help="List the words that you want to censor.")
parser.add_argument('--horde_censor_nsfw', action='store_true', required=False, help="Set to true if you want this bridge worker to censor NSFW images.")
parser.add_argument('--horde_model', action='store', required=False, help="Which model to run on this horde.")
opt = parser.parse_args()
with server_state_lock["bridge"]:
@ -206,6 +208,8 @@ def layout():
if __name__ == '__main__':
set_logger_verbosity(opt.verbosity)
quiesce_logger(opt.quiet)
if not opt.headless:
layout()
@ -214,14 +218,14 @@ if __name__ == '__main__':
try:
import bridgeData as cd
except ModuleNotFoundError as e:
print("No bridgeData found. Falling back to default where no CLI args are set.")
print(str(e))
logger.warning("No bridgeData found. Falling back to default where no CLI args are set.")
logger.debug(str(e))
except SyntaxError as e:
print("bridgeData found, but is malformed. Falling back to default where no CLI args are set.")
print(str(e))
logger.warning("bridgeData found, but is malformed. Falling back to default where no CLI args are set.")
logger.debug(str(e))
except Exception as e:
print("No bridgeData found, use default where no CLI args are set")
print(str(e))
logger.warning("No bridgeData found, use default where no CLI args are set")
logger.debug(str(e))
finally:
try: # check if cd exists (i.e. bridgeData loaded properly)
cd
@ -239,12 +243,18 @@ if __name__ == '__main__':
self.horde_priority_usernames = []
self.horde_max_power = 8
self.nsfw = True
self.censor_nsfw = False
self.blacklist = []
self.censorlist = []
self.models_to_load = ["stable_diffusion"]
cd = temp()
horde_api_key = opt.horde_api_key if opt.horde_api_key else cd.horde_api_key
horde_name = opt.horde_name if opt.horde_name else cd.horde_name
horde_url = opt.horde_url if opt.horde_url else cd.horde_url
horde_priority_usernames = opt.horde_priority_usernames if opt.horde_priority_usernames else cd.horde_priority_usernames
horde_max_power = opt.horde_max_power if opt.horde_max_power else cd.horde_max_power
# Not used yet
horde_models = [args.horde_model] if args.horde_model else bd.models_to_load
try:
horde_nsfw = not opt.horde_sfw if opt.horde_sfw else cd.horde_nsfw
except AttributeError: