-
-
Notifications
You must be signed in to change notification settings - Fork 302
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
119 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import os, sys | ||
import gradio as gr | ||
import importlib.util | ||
import tabs.plugins.plugins_core as plugins_core | ||
|
||
from assets.i18n.i18n import I18nAuto | ||
|
||
i18n = I18nAuto() | ||
|
||
now_dir = os.getcwd() | ||
sys.path.append(now_dir) | ||
|
||
plugins_core.check_new_folders() | ||
|
||
def plugins_tab(): | ||
gr.Markdown( | ||
value=i18n( | ||
"This section contains some extra utilities that often may be in experimental phases." | ||
) | ||
) | ||
|
||
with gr.TabItem(i18n("Install Plugins")): | ||
dropbox = gr.File( | ||
label=i18n( | ||
"Drag your plugin.zip to install it." | ||
), | ||
type="filepath", | ||
) | ||
|
||
dropbox.upload( | ||
fn=plugins_core.save_plugin_dropbox, | ||
inputs=[dropbox], | ||
outputs=[dropbox], | ||
) | ||
|
||
for plugin in os.listdir(os.path.join(now_dir, "tabs", "plugins", "installed")): | ||
plugin_main = f"tabs.plugins.installed.{plugin}.plugin" | ||
plugin_import = importlib.import_module(plugin_main) | ||
|
||
with gr.TabItem(plugin): | ||
plugin_import.applio_plugin() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
import os, sys, shutil | ||
import json | ||
import gradio as gr | ||
import zipfile | ||
import subprocess | ||
|
||
from assets.i18n.i18n import I18nAuto | ||
|
||
i18n = I18nAuto() | ||
|
||
now_dir = os.getcwd() | ||
sys.path.append(now_dir) | ||
|
||
plugins_path = os.path.join(now_dir, "tabs", "plugins", "installed") | ||
json_file_path = os.path.join(now_dir, "tabs", "plugins", "installed_list.json") | ||
current_folders = os.listdir(plugins_path) | ||
|
||
def get_existing_folders(): | ||
if os.path.exists(json_file_path): | ||
with open(json_file_path, 'r') as file: | ||
return json.load(file) | ||
else: | ||
return [] | ||
|
||
def save_existing_folders(existing_folders): | ||
with open(json_file_path, 'w') as file: | ||
json.dump(existing_folders, file) | ||
|
||
def save_plugin_dropbox(dropbox): | ||
if "zip" not in dropbox: | ||
raise gr.Error( | ||
message="The file you dropped is not a valid plugin.zip. Please try again." | ||
) | ||
else: | ||
file_name = (os.path.basename(dropbox)) | ||
folder_name = (file_name.split(".zip")[0]) | ||
folder_path = os.path.join(plugins_path, folder_name) | ||
zip_file_path = os.path.join(plugins_path, file_name) | ||
|
||
if os.path.exists(folder_name): | ||
os.remove(folder_name) | ||
|
||
shutil.move(dropbox, os.path.join(plugins_path, file_name)) | ||
print("Proceeding with the extraction...") | ||
|
||
with zipfile.ZipFile(zip_file_path, "r") as zip_ref: | ||
zip_ref.extractall(plugins_path) | ||
os.remove(zip_file_path) | ||
|
||
if os.path.exists(os.path.join(folder_path, "requirements.txt")): | ||
subprocess.run([os.path.join("env", "python.exe"), "-m", "pip", "install", "-r", os.path.join(folder_path, "requirements.txt")]) | ||
else: | ||
print("No requirements.txt file found in the plugin folder.") | ||
|
||
save_existing_folders(get_existing_folders() + [folder_name]) | ||
|
||
print(f"{folder_name} plugin installed in {plugins_path}! Restart applio to see the changes.") | ||
gr.Info(f"{folder_name} plugin installed in {plugins_path}! Restart applio to see the changes.") | ||
return None | ||
|
||
def check_new_folders(): | ||
existing_folders = get_existing_folders() | ||
new_folders = set(current_folders) - set(existing_folders) | ||
if new_folders: | ||
for new_folder in new_folders: | ||
complete_path = os.path.join(plugins_path, new_folder) | ||
print(f"New Plugin {new_folder} found! Installing...") | ||
|
||
if os.path.exists(os.path.join(complete_path, "requirements.txt")): | ||
subprocess.run([os.path.join("env", "python.exe"), "-m", "pip", "install", "-r", os.path.join(complete_path, "requirements.txt")]) | ||
else: | ||
print("No requirements.txt file found in the plugin folder.") | ||
print("Plugins checked and installed! Restart applio to see the changes.") | ||
save_existing_folders(current_folders) |