diff --git a/app.py b/app.py index a0a8d2c..7f065f8 100644 --- a/app.py +++ b/app.py @@ -1,55 +1,34 @@ import gradio as gr from processing.stacking import stacking +import sys +import importlib +import pathlib +import os +import copy +from tabs import tabs +tabs_dir = pathlib.Path(__file__).parent / "tabs" + + +all_tabs = [] +tab = None +for tab_name in tabs: + old_path = copy.deepcopy(sys.path) + sys.path = [os.path.join(tabs_dir, tab_name)] + sys.path + try: + if tab is None: + tab = importlib.import_module(f"app") + else: + tab = importlib.reload(tab) + all_tabs.append((tab_name, tab.app)) + + except Exception as e: + print(f"Error loading tab: {e}") with gr.Blocks() as app: - with gr.Tab("Stacking"): - gr.Markdown("Stacking images.") - with gr.Row(): - with gr.Column(): - directory = gr.Text( - placeholder="A directory with many images of the same size", lines=1, label="Directory") - methods = gr.Dropdown( - choices=["denoise", "startracks", "noise extractor", "untrack"], value="denoise", label="Method") - submit = gr.Button("Submit") - - with gr.Column(): - output = gr.Gallery() - - submit.click(stacking, inputs=[ - directory, methods], outputs=[output]) - - with gr.Tab("Bulk processing"): - gr.Markdown( - "Mass processing of images one at a time and saving to video if needed. # **WIP, not working**") - with gr.Row(): - with gr.Column(): - directory = gr.Text( - placeholder="A directory with many images of the same size", lines=1, label="Directory") - methods = gr.Dropdown( - choices=["denoise", "startracks", "noise extractor", "untrack"], value="denoise", label="Method") - submit = gr.Button("Submit") - - with gr.Tab("Video to images"): - gr.Markdown( - "Convert video to images. # **WIP, not working**") - with gr.Row(): - with gr.Column(): - video = gr.Video(label="Video") - - format = gr.Radio( - choices=["png", "jpg"], value="png", label="Format of image") - submit = gr.Button("Submit") - - with gr.Tab("Images to video"): - gr.Markdown("Convert images to video. # **WIP, not working**") - with gr.Row(): - with gr.Column(): - directory = gr.Text( - placeholder="A directory with many images of the same size", lines=1, label="Directory") - - fps = gr.Number(label="FPS") - submit = gr.Button("Submit") + for tab_name, tab in all_tabs: + with gr.Tab(tab_name): + tab.render() app.launch() diff --git a/tabs/Bulk processing/app.py b/tabs/Bulk processing/app.py new file mode 100644 index 0000000..8045c68 --- /dev/null +++ b/tabs/Bulk processing/app.py @@ -0,0 +1,13 @@ +import gradio as gr +from processing.bulk import images_to_video + +with gr.Blocks() as app: + gr.Markdown( + "Mass processing of images one at a time and saving to video if needed. # **WIP, not working**") + with gr.Row(): + with gr.Column(): + directory = gr.Text( + placeholder="A directory with many images of the same size", lines=1, label="Directory") + methods = gr.Dropdown( + choices=["denoise", "startracks", "noise extractor", "untrack"], value="denoise", label="Method") + submit = gr.Button("Submit") diff --git a/tabs/Images to video/app.py b/tabs/Images to video/app.py new file mode 100644 index 0000000..3166125 --- /dev/null +++ b/tabs/Images to video/app.py @@ -0,0 +1,17 @@ +import gradio as gr +from processing.bulk import images_to_video + +with gr.Blocks() as app: + gr.Markdown("Convert images to video. # **WIP, not working**") + with gr.Row(): + with gr.Column(): + directory = gr.Text( + placeholder="A directory with many images of the same size", lines=1, label="Directory") + + fps = gr.Number(label="FPS") + submit = gr.Button("Submit") + + submit.click( + fn=images_to_video, + inputs=[directory, fps], + ) diff --git a/tabs/Stacking/app.py b/tabs/Stacking/app.py new file mode 100644 index 0000000..48add4a --- /dev/null +++ b/tabs/Stacking/app.py @@ -0,0 +1,18 @@ +import gradio as gr +from processing.stacking import stacking + +with gr.Blocks() as app: + gr.Markdown("Stacking images.") + with gr.Row(): + with gr.Column(): + directory = gr.Text( + placeholder="A directory with many images of the same size", lines=1, label="Directory") + methods = gr.Dropdown( + choices=["denoise", "startracks", "noise extractor", "untrack"], value="denoise", label="Method") + submit = gr.Button("Submit") + + with gr.Column(): + output = gr.Gallery() + + submit.click(stacking, inputs=[ + directory, methods], outputs=[output]) diff --git a/tabs/Video to images/app.py b/tabs/Video to images/app.py new file mode 100644 index 0000000..d11d6e8 --- /dev/null +++ b/tabs/Video to images/app.py @@ -0,0 +1,12 @@ +import gradio as gr + +with gr.Blocks() as app: + gr.Markdown( + "Convert video to images. # **WIP, not working**") + with gr.Row(): + with gr.Column(): + video = gr.Video(label="Video") + + format = gr.Radio( + choices=["png", "jpg"], value="png", label="Format of image") + submit = gr.Button("Submit") diff --git a/tabs/__init__.py b/tabs/__init__.py new file mode 100644 index 0000000..31152a6 --- /dev/null +++ b/tabs/__init__.py @@ -0,0 +1,6 @@ +tabs = [ + "Stacking", + "Bulk processing", + "Images to video", + "Video to images" +]