From 8951837d04f30aa86f7cdf777c931303725d55ec Mon Sep 17 00:00:00 2001 From: Paillat Date: Fri, 23 Feb 2024 10:45:59 +0100 Subject: [PATCH] =?UTF-8?q?=F0=9F=94=A7=20chore(ui):=20refactor=20imports?= =?UTF-8?q?=20and=20remove=20unused=20code=20in=20=5F=5Finit=5F=5F.py=20an?= =?UTF-8?q?d=20gradio=5Fui.py=20=F0=9F=94=A5=20chore(ui):=20remove=20unuse?= =?UTF-8?q?d=20launcher.py=20file=20The=20imports=20in=20=5F=5Finit=5F=5F.?= =?UTF-8?q?py=20and=20gradio=5Fui.py=20have=20been=20refactored=20to=20rem?= =?UTF-8?q?ove=20the=20unused=20import=20statements.=20The=20launcher.py?= =?UTF-8?q?=20file=20has=20been=20removed=20as=20it=20is=20no=20longer=20n?= =?UTF-8?q?eeded.=20This=20improves=20code=20cleanliness=20and=20reduces?= =?UTF-8?q?=20unnecessary=20clutter.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ui/__init__.py | 3 +-- ui/gradio_ui.py | 18 ++++++++++++------ ui/launcher.py | 6 ------ 3 files changed, 13 insertions(+), 14 deletions(-) delete mode 100644 ui/launcher.py diff --git a/ui/__init__.py b/ui/__init__.py index f8a2755..43fcf69 100644 --- a/ui/__init__.py +++ b/ui/__init__.py @@ -1,2 +1 @@ -from .gradio_ui import GenerateUI -from .launcher import launch \ No newline at end of file +from .gradio_ui import GenerateUI, launch diff --git a/ui/gradio_ui.py b/ui/gradio_ui.py index d6276fb..d5d1e1c 100644 --- a/ui/gradio_ui.py +++ b/ui/gradio_ui.py @@ -1,4 +1,3 @@ -import os import gradio as gr import orjson import sys @@ -6,12 +5,14 @@ import sys from src.engines import ENGINES, BaseEngine from src.chore import GenerationContext + class GenerateUI: def __init__(self): self.css = """.generate_button { font-size: 5rem !important } """ + def get_presets(self): with open("local/presets.json", "r") as f: return orjson.loads(f.read()) @@ -35,8 +36,8 @@ class GenerateUI: return ui def launch_ui(self): - self.ui = self.get_ui() - self.ui.launch() + ui = self.get_ui() + ui.launch() def get_interfaces(self) -> tuple[list[gr.Blocks], list[str]]: """ @@ -53,9 +54,9 @@ class GenerateUI: def get_settings_interface(self) -> gr.Blocks: with gr.Blocks() as interface: reload_ui = gr.Button("Reload UI", variant="primary") + def reload(): - self.ui.close() - sys.exit("Reload") + gr.Warning("Please restart the server to apply changes.") reload_ui.click(reload) for engine_type, engines in ENGINES.items(): @@ -201,4 +202,9 @@ class GenerateUI: else: # we don't care about this, it's not the selected engine, we throw it away args = args[engine.num_options :] - return options \ No newline at end of file + return options + + +def launch(): + ui_generator = GenerateUI() + ui_generator.launch_ui() diff --git a/ui/launcher.py b/ui/launcher.py deleted file mode 100644 index cd02a10..0000000 --- a/ui/launcher.py +++ /dev/null @@ -1,6 +0,0 @@ -from . import GenerateUI - - -def launch(): - ui_generator = GenerateUI() - ui_generator.launch_ui()