new middleware handler and ability to restart server on-the-fly

This commit is contained in:
Vladimir Mandic
2023-04-16 15:57:00 -04:00
parent b7e4b0414a
commit 58df74cfd5
14 changed files with 145 additions and 125 deletions
+15
View File
@@ -632,6 +632,8 @@ def reload_gradio_theme(theme_name=None):
print("Theme download error accessing HuggingFace")
gradio_theme = gr.themes.Default()
print(f'Loading theme: {theme_name}')
if demo is not None:
demo.close()
class TotalTQDM:
@@ -673,6 +675,19 @@ mem_mon = modules.memmon.MemUsageMonitor("MemMon", device, opts)
mem_mon.start()
def restart_server():
if demo is None:
return
try:
demo.server.should_exit = True
demo.server.force_exit = True
demo.close(verbose=False)
demo.server.close()
except:
pass
print('Server shutdown')
def listfiles(dirname):
filenames = [os.path.join(dirname, x) for x in sorted(os.listdir(dirname), key=str.lower) if not x.startswith(".")]
return [file for file in filenames if os.path.isfile(file)]