Skip to content
Python

added sample plugin app and improved plugin api

DeepBeepMeepc53cabfd3717
diff --git a/README.md b/README.md
index 4bc121e..bf5c830 100644
--- a/README.md
+++ b/README.md
@@ -36,12 +36,14 @@ WanGP supports the Wan (and derived models), Hunyuan Video and LTV Video models
-----
## 🔥 Latest Updates :
-### November 1 2025: WanGP v9.3, How many bananas is too many bananas ?
+### November 5 2025: WanGP v9.35, How many bananas are too many bananas ?
**Chrono Edit**: a new original way to edit an Image. This one will generate a Video will that performs the full edition work and return the last Image. It can be hit or a miss but when it works it is quite impressive. Please note you must absolutely use the *Prompt Enhancer* on your *Prompt Instruction* because this model expects a very specific format. The Prompt Enhancer for this model has a specific System Prompt to generate the right Chrono Edit Prompt.
**LyCoris** support: preliminary basic Lycoris support for this Lora format. At least Qwen Multi Camera should work (https://huggingface.co/dx8152/Qwen-Edit-2509-Multiple-angles). If you have a Lycoris that does not work and it may be interesting please mention it in the Request Channel
+*update 9.35*: Added a Sample PlugIn App that shows how to collect and modify settings from a PlugIn
+
### October 29 2025: WanGP v9.21, Why isn't all my VRAM used ?
diff --git a/docs/PLUGINS.md b/docs/PLUGINS.md
index fc5f50a..f2840f8 100644
--- a/docs/PLUGINS.md
+++ b/docs/PLUGINS.md
@@ -21,10 +21,16 @@ This system allows you to extend and customize the Wan2GP user interface and fun
Plugins are standard Python packages (folders) located within the main `plugins/` directory. This structure allows for multiple files, dependencies, and proper packaging.
+Don't hesitate to have a look at the Sample PlugIn "wan2gp_sample" as it illustrates:
+-How to get Settings from the Main Form and then Modify them
+-How to suspend the Video Gen (and release VRAM) to execute your own GPU intensive process.
+-How to switch back automatically to the Main Tab
+
A valid plugin folder must contain at a minimum:
* `__init__.py`: An empty file that tells Python to treat the directory as a package.
* `plugin.py`: The main file containing your class that inherits from `WAN2GPPlugin`.
+
A complete plugin folder typically looks like this:
```
diff --git a/plugins/wan2gp-sample/__init__.py b/plugins/wan2gp-sample/__init__.py
new file mode 100644
index 0000000..e69de29
diff --git a/plugins/wan2gp-sample/plugin.py b/plugins/wan2gp-sample/plugin.py
new file mode 100644
index 0000000..3fe26f2
--- /dev/null
+++ b/plugins/wan2gp-sample/plugin.py
@@ -0,0 +1,97 @@
+import gradio as gr
+from shared.utils.plugins import WAN2GPPlugin
+from shared.utils.process_locks import acquire_GPU_ressources, release_GPU_ressources, any_GPU_process_running
+import time
+
+PlugIn_Name = "Sample Plugin"
+PlugIn_Id ="SamplePlugin"
+
+def acquire_GPU(state):
+ GPU_process_running = any_GPU_process_running(state, PlugIn_Id)
+ if GPU_process_running:
+ gr.Error("Another PlugIn is using the GPU")
+ acquire_GPU_ressources(state, PlugIn_Id, PlugIn_Name, gr= gr)
+
+def release_GPU(state):
+ release_GPU_ressources(state, PlugIn_Id)
+
+class ConfigTabPlugin(WAN2GPPlugin):
+ def __init__(self):
+ super().__init__()
+ self.name = PlugIn_Name
+ self.version = "1.0.0"
+ self.description = PlugIn_Name
+
+ def setup_ui(self):
+ self.request_global("get_current_model_settings")
+ self.request_component("refresh_form_trigger")
+ self.request_component("state")
+ self.request_component("resolution")
+ self.request_component("main_tabs")
+
+ self.add_tab(
+ tab_id=PlugIn_Id,
+ label=PlugIn_Name,
+ component_constructor=self.create_config_ui,
+ )
+
+
+ def on_tab_select(self, state: dict) -> None:
+ settings = self.get_current_model_settings(state)
+ prompt = settings["prompt"]
+ return prompt
+
+
+ def on_tab_deselect(self, state: dict) -> None:
+ pass
+
+ def create_config_ui(self):
+ def update_prompt(state, text):
+ settings = self.get_current_model_settings(state)
+ settings["prompt"] = text
+ return time.time()
+
+ def big_process(state):
+ acquire_GPU(state)
+ gr.Info("Doing something important")
+ time.sleep(30)
+ release_GPU(state)
+ return "42"
+
+ def goto_video_tab(state):
+ return self.goto_video_tab(state)
+
+ with gr.Column():
+ state = self.state
+ settings = self.get_current_model_settings(state.value)
+ prompt = settings["prompt"]
+ gr.HTML("<B><B>Sample Plugin that illustrates</B>:<BR>-How to get Settings from Main Form and then Modify them<BR>-How to suspend the Video Gen (and release VRAM) to execute your own GPU intensive process.<BR>-How to switch back automatically to the Main Tab")
+ sample_text = gr.Text(label="Prompt Copy", value=prompt, lines=5)
+ update_btn = gr.Button("Update Prompt On Main Page")
+ gr.Markdown()
+ process_btn = gr.Button("Use GPU To Do Something Important")
+ process_output = gr.Text(label="Process Output", value='')
+ goto_btn = gr.Button("Goto Video Tab")
+
+ self.on_tab_outputs = [sample_text]
+
+ update_btn.click(
+ fn=update_prompt,
+ inputs=[state, sample_text],
+ outputs=[ self.refresh_form_trigger ]
+ )
+
+
+ process_btn.click(
+ fn=big_process,
+ inputs=[state],
+ outputs=[ process_output ]
+ )
+
+ goto_btn.click(
+ fn=goto_video_tab,
+ inputs=[state],
+ outputs=[ self.main_tabs ]
+ )
+
+
\ No newline at end of file
diff --git a/plugins/wan2gp-video-mask-creator/plugin.py b/plugins/wan2gp-video-mask-creator/plugin.py
index 8541ff0..f8ace19 100644
--- a/plugins/wan2gp-video-mask-creator/plugin.py
+++ b/plugins/wan2gp-video-mask-creator/plugin.py
@@ -40,6 +40,7 @@ class VideoMaskCreatorPlugin(WAN2GPPlugin):
server_config=self.server_config,
get_current_model_settings_fn=self.get_current_model_settings
)
+ self.matanyone_app.PlugIn = self
def on_tab_select(self, state: dict) -> None:
# print("[VideoMaskCreatorPlugin] Tab selected. Loading models...")
diff --git a/preprocessing/matanyone/app.py b/preprocessing/matanyone/app.py
index 2c6a38b..4007bf8 100644
--- a/preprocessing/matanyone/app.py
+++ b/preprocessing/matanyone/app.py
@@ -36,6 +36,8 @@ matanyone_model = None
model_in_GPU = False
matanyone_in_GPU = False
bfloat16_supported = False
+PlugIn = None
+
# SAM generator
import copy
GPU_process_was_running = False
@@ -898,9 +900,7 @@ def export_to_current_video_engine(state, foreground_video_output, alpha_video_o
def teleport_to_video_tab(tab_state, state):
- from wgp import set_new_tab
- set_new_tab(tab_state, state, 0)
- return gr.Tabs(selected="video_gen")
+ return PlugIn.goto_video_tab(state)
def display(tabs, tab_state, state, refresh_form_trigger, server_config, get_current_model_settings_fn): #, vace_video_input, vace_image_input, vace_video_mask, vace_image_mask, vace_image_refs):
diff --git a/shared/utils/plugins.py b/shared/utils/plugins.py
index 177d7fa..a351fcd 100644
--- a/shared/utils/plugins.py
+++ b/shared/utils/plugins.py
@@ -12,7 +12,7 @@ import git
import shutil
import stat
import json
-
+video_gen_label = "Video Generator"
def auto_install_and_enable_default_plugins(manager: 'PluginManager', wgp_globals: dict):
server_config = wgp_globals.get("server_config")
server_config_filename = wgp_globals.get("server_config_filename")
@@ -489,9 +489,9 @@ class WAN2GPApplication:
self.plugin_manager.load_plugins_from_directory(self.enabled_plugins)
self.plugin_manager.inject_globals(wgp_globals)
- def setup_ui_tabs(self, main_tabs_component: gr.Tabs, state_component: gr.State):
+ def setup_ui_tabs(self, main_tabs_component: gr.Tabs, state_component: gr.State, set_save_form_event):
self._create_plugin_tabs()
- self._setup_tab_events(main_tabs_component, state_component)
+ self._setup_tab_events(main_tabs_component, state_component, set_save_form_event)
def _create_plugin_tabs(self):
if not hasattr(self, 'plugin_manager'):
@@ -523,7 +523,7 @@ class WAN2GPApplication:
self.all_rendered_tabs.append(new_tab)
tab_info['component_constructor']()
- def _setup_tab_events(self, main_tabs_component: gr.Tabs, state_component: gr.State):
+ def _setup_tab_events(self, main_tabs_component: gr.Tabs, state_component: gr.State, set_save_form_event):
if main_tabs_component and state_component:
main_tabs_component.select(
fn=self._handle_tab_selection,
@@ -531,12 +531,39 @@ class WAN2GPApplication:
outputs=None,
show_progress="hidden",
)
+
+ def goto_video_tab(state):
+ self._handle_tab_selection(state, None)
+ return gr.Tabs(selected="video_gen")
+
+ for tab in self.all_rendered_tabs:
+ # def test_tab(state_component, evt: gr.SelectData):
+ # last_save_form = state_component.get("last_save_form", video_gen_label)
+ # if last_save_form != video_gen_label :
+ # state_component["ignore_save_form"] = True
+ # else:
+ # state_component["last_save_form"] = evt.value
+
+
+ plugin = self.tab_to_plugin_map[tab.label]
+ plugin.goto_video_tab = goto_video_tab
+ # event = tab.select(fn=test_tab, inputs=[state_component])
+ # event = set_save_form_event(event.then)
+ event = set_save_form_event(tab.select)
+ event.then(
+ fn=self._handle_one_tab_selection,
+ inputs=[state_component, gr.State(tab.label)],
+ outputs=plugin.on_tab_outputs if hasattr(plugin, "on_tab_outputs") else None,
+ show_progress="hidden",
+ trigger_mode="multiple",
+ )
+
def _handle_tab_selection(self, state: dict, evt: gr.SelectData):
if not hasattr(self, 'previous_tab_id'):
- self.previous_tab_id = "video_gen"
+ self.previous_tab_id = video_gen_label
- new_tab_id = evt.value
+ new_tab_id = video_gen_label if evt is None else evt.value
if self.previous_tab_id == new_tab_id:
return
@@ -549,16 +576,26 @@ class WAN2GPApplication:
print(f"[PluginManager] Error in on_tab_deselect for plugin {plugin_to_deselect.name}: {e}")
traceback.print_exc()
- if new_tab_id and new_tab_id in self.tab_to_plugin_map:
- plugin_to_select = self.tab_to_plugin_map[new_tab_id]
- try:
- plugin_to_select.on_tab_select(state)
- except Exception as e:
- print(f"[PluginManager] Error in on_tab_select for plugin {plugin_to_select.name}: {e}")
- traceback.print_exc()
+ # if new_tab_id and new_tab_id in self.tab_to_plugin_map:
+ # plugin_to_select = self.tab_to_plugin_map[new_tab_id]
+ # if not hasattr(plugin_to_select, "on_tab_outputs"):
+ # try:
+ # plugin_to_select.on_tab_select(state)
+ # except Exception as e:
+ # print(f"[PluginManager] Error in on_tab_select for plugin {plugin_to_select.name}: {e}")
+ # traceback.print_exc()
self.previous_tab_id = new_tab_id
-
+
+ def _handle_one_tab_selection(self, state: dict, new_tab_id): #, evt: gr.SelectData
+ plugin_to_select = self.tab_to_plugin_map.get(new_tab_id, None)
+ try:
+ ret = plugin_to_select.on_tab_select(state)
+ except Exception as e:
+ print(f"[PluginManager] Error in on_tab_select for plugin {plugin_to_select.name}: {e}")
+ traceback.print_exc()
+ return ret
+
def run_component_insertion(self, components_dict: Dict[str, Any]):
if hasattr(self, 'plugin_manager'):
self.plugin_manager.run_component_insertion_and_setup(components_dict)
diff --git a/wgp.py b/wgp.py
index faf0a5c..202b7b1 100644
--- a/wgp.py
+++ b/wgp.py
@@ -7403,6 +7403,8 @@ def save_inputs(
plugin_data,
):
+ if state.pop("ignore_save_form", False):
+ return
model_type = state["model_type"]
if image_mask_guide is not None and image_mode >= 1 and video_prompt_type is not None and "A" in video_prompt_type and not "U" in video_prompt_type:
@@ -9249,15 +9251,18 @@ def generate_video_tab(update_form = False, state_dict = None, ui_defaults = Non
outputs= None
).then( fn=enhance_prompt, inputs =[state, prompt, prompt_enhancer, multi_images_gen_type, override_profile ] , outputs= [prompt, wizard_prompt])
- save_form_trigger.change(fn=validate_wizard_prompt,
- inputs= [state, wizard_prompt_activated_var, wizard_variables_var, prompt, wizard_prompt, *prompt_vars] ,
- outputs= [prompt],
- show_progress="hidden",
- ).then(fn=save_inputs,
- inputs =[target_state] + gen_inputs,
- outputs= None
- )
+ # save_form_trigger.change(fn=validate_wizard_prompt,
+ def set_save_form_event(trigger):
+ return trigger(fn=validate_wizard_prompt,
+ inputs= [state, wizard_prompt_activated_var, wizard_variables_var, prompt, wizard_prompt, *prompt_vars] ,
+ outputs= [prompt],
+ show_progress="hidden",
+ ).then(fn=save_inputs,
+ inputs =[target_state] + gen_inputs,
+ outputs= None
+ )
+ set_save_form_event(save_form_trigger.change)
gr.on(triggers=[video_info_eject_video_btn.click, video_info_eject_video2_btn.click, video_info_eject_video3_btn.click, video_info_eject_image_btn.click], fn=eject_video_from_gallery, inputs =[state, output, last_choice], outputs = [output, video_info, video_buttons_row] )
video_info_to_control_video_btn.click(fn=video_to_control_video, inputs =[state, output, last_choice], outputs = [video_guide] )
video_info_to_video_source_btn.click(fn=video_to_source_video, inputs =[state, output, last_choice], outputs = [video_source] )
@@ -9352,7 +9357,7 @@ def generate_video_tab(update_form = False, state_dict = None, ui_defaults = Non
)
if tab_id == 'generate':
- main_tabs.select(fn=detect_auto_save_form, inputs= [state], outputs= save_form_trigger, trigger_mode="multiple")
+ # main_tabs.select(fn=detect_auto_save_form, inputs= [state], outputs= save_form_trigger, trigger_mode="multiple")
model_family.input(fn=change_model_family, inputs=[state, model_family], outputs= [model_base_type_choice, model_choice], show_progress="hidden")
model_base_type_choice.input(fn=change_model_base_types, inputs=[state, model_family, model_base_type_choice], outputs= [model_base_type_choice, model_choice], show_progress="hidden")
@@ -10467,7 +10472,7 @@ def create_ui():
outputs=[generator_tab_components['queue_html'], main_tabs, edit_tab],
show_progress="hidden"
)
- app.setup_ui_tabs(main_tabs, state)
+ app.setup_ui_tabs(main_tabs, state, generator_tab_components["set_save_form_event"])
if stats_app is not None:
stats_app.setup_events(main, state)
return main