From 043908b802f8d47228d701d51a8904af4d2ce9ec Mon Sep 17 00:00:00 2001 From: Saifeddine ALOUI Date: Tue, 26 Nov 2024 15:38:16 +0100 Subject: [PATCH 01/11] Update comfyui_nodes.py --- demos/comfyui_nodes.py | 55 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) diff --git a/demos/comfyui_nodes.py b/demos/comfyui_nodes.py index e69de29..4c7e90e 100644 --- a/demos/comfyui_nodes.py +++ b/demos/comfyui_nodes.py @@ -0,0 +1,55 @@ +#! /usr/bin/env python + +import sys +import click +import gradio as gr + +sys.path.append("..") +from cli import configure_model, generate_video + +with gr.Blocks() as demo: + gr.Markdown("Video Generator") + with gr.Row(): + prompt = gr.Textbox( + label="Prompt", + value="A hand with delicate fingers picks up a bright yellow lemon from a wooden bowl filled with lemons and sprigs of mint against a peach-colored background. The hand gently tosses the lemon up and catches it, showcasing its smooth texture. A beige string bag sits beside the bowl, adding a rustic touch to the scene. Additional lemons, one halved, are scattered around the base of the bowl. The even lighting enhances the vibrant colors and creates a fresh, inviting atmosphere.", + ) + negative_prompt = gr.Textbox(label="Negative Prompt", value="") + seed = gr.Number(label="Seed", value=1710977262, precision=0) + with gr.Row(): + width = gr.Number(label="Width", value=848, precision=0) + height = gr.Number(label="Height", value=480, precision=0) + num_frames = gr.Number(label="Number of Frames", value=163, precision=0) + with gr.Row(): + cfg_scale = gr.Number(label="CFG Scale", value=4.5) + num_inference_steps = gr.Number(label="Number of Inference Steps", value=200, precision=0) + btn = gr.Button("Generate Video") + output = gr.Video() + + btn.click( + generate_video, + inputs=[ + prompt, + negative_prompt, + width, + height, + num_frames, + seed, + cfg_scale, + num_inference_steps, + ], + outputs=output, + ) + + +@click.command() +@click.option("--model_dir", required=True, help="Path to the model directory.") +@click.option("--cpu_offload", is_flag=True, help="Whether to offload model to CPU") +@click.option("--port", default=7860, help="Port to run the server on") +def launch(model_dir, cpu_offload, port): + configure_model(model_dir, cpu_offload) + demo.launch(server_name="0.0.0.0", server_port=port) + + +if __name__ == "__main__": + launch() From 58c5df363736b446a87e71ec7fdef5ff9ff7e45c Mon Sep 17 00:00:00 2001 From: Saifeddine ALOUI Date: Tue, 26 Nov 2024 16:37:45 +0100 Subject: [PATCH 02/11] Update comfyui_nodes.py --- demos/comfyui_nodes.py | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/demos/comfyui_nodes.py b/demos/comfyui_nodes.py index 4c7e90e..8237e29 100644 --- a/demos/comfyui_nodes.py +++ b/demos/comfyui_nodes.py @@ -1,5 +1,6 @@ #! /usr/bin/env python +import os import sys import click import gradio as gr @@ -45,10 +46,24 @@ @click.command() @click.option("--model_dir", required=True, help="Path to the model directory.") @click.option("--cpu_offload", is_flag=True, help="Whether to offload model to CPU") +@click.option("--gpu_id", default="0", help="GPU ID to use (default: 0). Use 'cpu' to force CPU.") +@click.option("--host", default="0.0.0.0", help="Host to run the server on (default: 0.0.0.0). Use 'localhost' for local access only.") @click.option("--port", default=7860, help="Port to run the server on") -def launch(model_dir, cpu_offload, port): +def launch(model_dir, cpu_offload, gpu_id, host, port): + # Set the GPU to use + if gpu_id.lower() == "cpu": + os.environ["CUDA_VISIBLE_DEVICES"] = "" # Force CPU usage + print("Using CPU for computation.") + else: + os.environ["CUDA_VISIBLE_DEVICES"] = gpu_id # Set the specified GPU + print(f"Using GPU {gpu_id} for computation.") + + # Configure the model configure_model(model_dir, cpu_offload) - demo.launch(server_name="0.0.0.0", server_port=port) + + # Launch the Gradio app + print(f"Launching server on {host}:{port}") + demo.launch(server_name=host, server_port=port) if __name__ == "__main__": From 3089bfac48bae7efbe44f6c4a3efa9dec28ad69d Mon Sep 17 00:00:00 2001 From: Saifeddine ALOUI Date: Tue, 26 Nov 2024 16:38:58 +0100 Subject: [PATCH 03/11] Update gradio_ui.py --- demos/gradio_ui.py | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/demos/gradio_ui.py b/demos/gradio_ui.py index b750e9a..c48bb56 100755 --- a/demos/gradio_ui.py +++ b/demos/gradio_ui.py @@ -1,8 +1,7 @@ #! /usr/bin/env python - +import os import sys - import click import gradio as gr @@ -47,9 +46,24 @@ @click.command() @click.option("--model_dir", required=True, help="Path to the model directory.") @click.option("--cpu_offload", is_flag=True, help="Whether to offload model to CPU") -def launch(model_dir, cpu_offload): +@click.option("--gpu_id", default="0", help="GPU ID to use (default: 0). Use 'cpu' to force CPU.") +@click.option("--host", default="0.0.0.0", help="Host to run the server on (default: 0.0.0.0). Use 'localhost' for local access only.") +@click.option("--port", default=7860, help="Port to run the server on") +def launch(model_dir, cpu_offload, gpu_id, host, port): + # Set the GPU to use + if gpu_id.lower() == "cpu": + os.environ["CUDA_VISIBLE_DEVICES"] = "" # Force CPU usage + print("Using CPU for computation.") + else: + os.environ["CUDA_VISIBLE_DEVICES"] = gpu_id # Set the specified GPU + print(f"Using GPU {gpu_id} for computation.") + + # Configure the model configure_model(model_dir, cpu_offload) - demo.launch() + + # Launch the Gradio app + print(f"Launching server on {host}:{port}") + demo.launch(server_name=host, server_port=port) if __name__ == "__main__": From aeed01600d9e319ab8f70adeda2a1121a0a267a2 Mon Sep 17 00:00:00 2001 From: Saifeddine ALOUI Date: Tue, 26 Nov 2024 17:29:47 +0100 Subject: [PATCH 04/11] added .vscode to gitignore --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index f30911a..8e01322 100644 --- a/.gitignore +++ b/.gitignore @@ -7,3 +7,4 @@ genmo.egg-info outputs build .ruff_cache +.vscode \ No newline at end of file From 778b00a5ceddf0aee618cefa6e5e8c92d86ab219 Mon Sep 17 00:00:00 2001 From: Saifeddine ALOUI Date: Wed, 27 Nov 2024 10:09:46 +0100 Subject: [PATCH 05/11] Update gradio_ui.py --- demos/gradio_ui.py | 47 ++++++++++++++++++++++++++++++++-------------- 1 file changed, 33 insertions(+), 14 deletions(-) diff --git a/demos/gradio_ui.py b/demos/gradio_ui.py index b750e9a..f5fd25c 100755 --- a/demos/gradio_ui.py +++ b/demos/gradio_ui.py @@ -1,32 +1,45 @@ #! /usr/bin/env python - import sys - import click import gradio as gr sys.path.append("..") from cli import configure_model, generate_video -with gr.Blocks() as demo: - gr.Markdown("Video Generator") +# Enhanced Gradio App +with gr.Blocks(css=".gradio-container {font-family: 'Arial', sans-serif; background-color: #f9f9f9;}") as demo: + gr.Markdown( + """ +

🎥 Video Generator

+

Generate stunning videos with ease!

+ """, + elem_id="header", + ) with gr.Row(): prompt = gr.Textbox( label="Prompt", value="A hand with delicate fingers picks up a bright yellow lemon from a wooden bowl filled with lemons and sprigs of mint against a peach-colored background. The hand gently tosses the lemon up and catches it, showcasing its smooth texture. A beige string bag sits beside the bowl, adding a rustic touch to the scene. Additional lemons, one halved, are scattered around the base of the bowl. The even lighting enhances the vibrant colors and creates a fresh, inviting atmosphere.", + lines=3, + placeholder="Enter your prompt here...", ) - negative_prompt = gr.Textbox(label="Negative Prompt", value="") + negative_prompt = gr.Textbox( + label="Negative Prompt", + value="", + lines=2, + placeholder="Enter negative prompt here...", + ) + with gr.Row(): seed = gr.Number(label="Seed", value=1710977262, precision=0) + cfg_scale = gr.Number(label="CFG Scale", value=4.5) with gr.Row(): width = gr.Number(label="Width", value=848, precision=0) height = gr.Number(label="Height", value=480, precision=0) - num_frames = gr.Number(label="Number of Frames", value=163, precision=0) with gr.Row(): - cfg_scale = gr.Number(label="CFG Scale", value=4.5) + num_frames = gr.Number(label="Number of Frames", value=163, precision=0) num_inference_steps = gr.Number(label="Number of Inference Steps", value=200, precision=0) - btn = gr.Button("Generate Video") - output = gr.Video() + btn = gr.Button("🎬 Generate Video", elem_id="generate-btn") + output = gr.Video(label="Generated Video") btn.click( generate_video, @@ -43,13 +56,19 @@ outputs=output, ) - +# Command-line interface with GPU, host, and port options @click.command() @click.option("--model_dir", required=True, help="Path to the model directory.") -@click.option("--cpu_offload", is_flag=True, help="Whether to offload model to CPU") -def launch(model_dir, cpu_offload): - configure_model(model_dir, cpu_offload) - demo.launch() +@click.option("--cpu_offload", is_flag=True, help="Whether to offload model to CPU.") +@click.option("--gpu", default=None, help="Specify the GPU to use (e.g., 'cuda:0').") +@click.option("--host", default="127.0.0.1", help="Host address for the Gradio app.") +@click.option("--port", default=7860, help="Port number for the Gradio app.") +def launch(model_dir, cpu_offload, gpu, host, port): + # Configure the model + configure_model(model_dir, cpu_offload, gpu=gpu) + + # Launch the Gradio app + demo.launch(server_name=host, server_port=port) if __name__ == "__main__": From 7fe20352cbbfe88730d3ff3221c0b0b763dd99e3 Mon Sep 17 00:00:00 2001 From: Saifeddine ALOUI Date: Wed, 27 Nov 2024 10:13:41 +0100 Subject: [PATCH 06/11] Update cli.py --- demos/cli.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/demos/cli.py b/demos/cli.py index b30cc88..b444ae4 100755 --- a/demos/cli.py +++ b/demos/cli.py @@ -25,12 +25,20 @@ cpu_offload = False -def configure_model(model_dir_path_, lora_path_, cpu_offload_): +def configure_model(model_dir_path_, lora_path_, cpu_offload_, gpu=None): global model_dir_path, lora_path, cpu_offload model_dir_path = model_dir_path_ lora_path = lora_path_ cpu_offload = cpu_offload_ + # Set the GPU device if specified + if gpu: + os.environ["CUDA_VISIBLE_DEVICES"] = gpu + print(f"Using GPU: {gpu}") + else: + print("Using default GPU configuration.") + + def load_model(): global num_gpus, pipeline, model_dir_path, lora_path From d524b51f2ddca9640e4817d78dab3154c80ba2d0 Mon Sep 17 00:00:00 2001 From: Saifeddine ALOUI Date: Wed, 27 Nov 2024 10:14:17 +0100 Subject: [PATCH 07/11] Update gradio_ui.py --- demos/gradio_ui.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/demos/gradio_ui.py b/demos/gradio_ui.py index f5fd25c..df366ec 100755 --- a/demos/gradio_ui.py +++ b/demos/gradio_ui.py @@ -59,13 +59,14 @@ # Command-line interface with GPU, host, and port options @click.command() @click.option("--model_dir", required=True, help="Path to the model directory.") +@click.option("--lora_path", required=False, help="Path to the lora file.") @click.option("--cpu_offload", is_flag=True, help="Whether to offload model to CPU.") @click.option("--gpu", default=None, help="Specify the GPU to use (e.g., 'cuda:0').") @click.option("--host", default="127.0.0.1", help="Host address for the Gradio app.") @click.option("--port", default=7860, help="Port number for the Gradio app.") -def launch(model_dir, cpu_offload, gpu, host, port): +def launch(model_dir, lora_path, cpu_offload, gpu, host, port): # Configure the model - configure_model(model_dir, cpu_offload, gpu=gpu) + configure_model(model_dir, lora_path, cpu_offload, gpu=gpu) # Launch the Gradio app demo.launch(server_name=host, server_port=port) From 9215499a3a360170d73ee697d59fa8bb585e3d24 Mon Sep 17 00:00:00 2001 From: Saifeddine ALOUI Date: Wed, 27 Nov 2024 10:39:31 +0100 Subject: [PATCH 08/11] Update gradio_ui.py --- demos/gradio_ui.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/demos/gradio_ui.py b/demos/gradio_ui.py index df366ec..ac0716c 100755 --- a/demos/gradio_ui.py +++ b/demos/gradio_ui.py @@ -11,7 +11,7 @@ with gr.Blocks(css=".gradio-container {font-family: 'Arial', sans-serif; background-color: #f9f9f9;}") as demo: gr.Markdown( """ -

🎥 Video Generator

+

🎥 Mochi Video Generator

Generate stunning videos with ease!

""", elem_id="header", From 1fdc192967ef0181fddded93c44e38ce8d82a386 Mon Sep 17 00:00:00 2001 From: Saifeddine ALOUI Date: Wed, 27 Nov 2024 21:04:06 +0100 Subject: [PATCH 09/11] Update comfyui_nodes.py --- demos/comfyui_nodes.py | 69 ------------------------------------------ 1 file changed, 69 deletions(-) diff --git a/demos/comfyui_nodes.py b/demos/comfyui_nodes.py index 8237e29..d3f5a12 100644 --- a/demos/comfyui_nodes.py +++ b/demos/comfyui_nodes.py @@ -1,70 +1 @@ -#! /usr/bin/env python -import os -import sys -import click -import gradio as gr - -sys.path.append("..") -from cli import configure_model, generate_video - -with gr.Blocks() as demo: - gr.Markdown("Video Generator") - with gr.Row(): - prompt = gr.Textbox( - label="Prompt", - value="A hand with delicate fingers picks up a bright yellow lemon from a wooden bowl filled with lemons and sprigs of mint against a peach-colored background. The hand gently tosses the lemon up and catches it, showcasing its smooth texture. A beige string bag sits beside the bowl, adding a rustic touch to the scene. Additional lemons, one halved, are scattered around the base of the bowl. The even lighting enhances the vibrant colors and creates a fresh, inviting atmosphere.", - ) - negative_prompt = gr.Textbox(label="Negative Prompt", value="") - seed = gr.Number(label="Seed", value=1710977262, precision=0) - with gr.Row(): - width = gr.Number(label="Width", value=848, precision=0) - height = gr.Number(label="Height", value=480, precision=0) - num_frames = gr.Number(label="Number of Frames", value=163, precision=0) - with gr.Row(): - cfg_scale = gr.Number(label="CFG Scale", value=4.5) - num_inference_steps = gr.Number(label="Number of Inference Steps", value=200, precision=0) - btn = gr.Button("Generate Video") - output = gr.Video() - - btn.click( - generate_video, - inputs=[ - prompt, - negative_prompt, - width, - height, - num_frames, - seed, - cfg_scale, - num_inference_steps, - ], - outputs=output, - ) - - -@click.command() -@click.option("--model_dir", required=True, help="Path to the model directory.") -@click.option("--cpu_offload", is_flag=True, help="Whether to offload model to CPU") -@click.option("--gpu_id", default="0", help="GPU ID to use (default: 0). Use 'cpu' to force CPU.") -@click.option("--host", default="0.0.0.0", help="Host to run the server on (default: 0.0.0.0). Use 'localhost' for local access only.") -@click.option("--port", default=7860, help="Port to run the server on") -def launch(model_dir, cpu_offload, gpu_id, host, port): - # Set the GPU to use - if gpu_id.lower() == "cpu": - os.environ["CUDA_VISIBLE_DEVICES"] = "" # Force CPU usage - print("Using CPU for computation.") - else: - os.environ["CUDA_VISIBLE_DEVICES"] = gpu_id # Set the specified GPU - print(f"Using GPU {gpu_id} for computation.") - - # Configure the model - configure_model(model_dir, cpu_offload) - - # Launch the Gradio app - print(f"Launching server on {host}:{port}") - demo.launch(server_name=host, server_port=port) - - -if __name__ == "__main__": - launch() From 364060590a82cefc1cf451c724c66ad65755753f Mon Sep 17 00:00:00 2001 From: Saifeddine ALOUI Date: Wed, 27 Nov 2024 21:05:10 +0100 Subject: [PATCH 10/11] Update comfyui_nodes.py From 5573fd1d54c284dc56d864fe80194b5617dc634a Mon Sep 17 00:00:00 2001 From: Saifeddine ALOUI Date: Sun, 1 Dec 2024 09:53:08 +0100 Subject: [PATCH 11/11] Update gradio_ui.py --- demos/gradio_ui.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/demos/gradio_ui.py b/demos/gradio_ui.py index ac0716c..84a05c9 100755 --- a/demos/gradio_ui.py +++ b/demos/gradio_ui.py @@ -61,7 +61,7 @@ @click.option("--model_dir", required=True, help="Path to the model directory.") @click.option("--lora_path", required=False, help="Path to the lora file.") @click.option("--cpu_offload", is_flag=True, help="Whether to offload model to CPU.") -@click.option("--gpu", default=None, help="Specify the GPU to use (e.g., 'cuda:0').") +@click.option("--gpu", default=None, help="Specify the GPU to use (e.g.: 0).") @click.option("--host", default="127.0.0.1", help="Host address for the Gradio app.") @click.option("--port", default=7860, help="Port number for the Gradio app.") def launch(model_dir, lora_path, cpu_offload, gpu, host, port):