Aitron Emper
commited on
Commit
•
6edc0a9
1
Parent(s):
87bb7d7
Upload 2 files
Browse files- tabs/plugins/plugins.py +34 -0
- tabs/plugins/plugins_core.py +102 -0
tabs/plugins/plugins.py
ADDED
@@ -0,0 +1,34 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import os, sys
|
2 |
+
import gradio as gr
|
3 |
+
import importlib.util
|
4 |
+
import tabs.plugins.plugins_core as plugins_core
|
5 |
+
|
6 |
+
from assets.i18n.i18n import I18nAuto
|
7 |
+
|
8 |
+
i18n = I18nAuto()
|
9 |
+
|
10 |
+
now_dir = os.getcwd()
|
11 |
+
sys.path.append(now_dir)
|
12 |
+
|
13 |
+
plugins_core.check_new_folders()
|
14 |
+
|
15 |
+
|
16 |
+
def plugins_tab():
|
17 |
+
with gr.TabItem(i18n("Plugin Installer")):
|
18 |
+
dropbox = gr.File(
|
19 |
+
label=i18n("Drag your plugin.zip to install it"),
|
20 |
+
type="filepath",
|
21 |
+
)
|
22 |
+
|
23 |
+
dropbox.upload(
|
24 |
+
fn=plugins_core.save_plugin_dropbox,
|
25 |
+
inputs=[dropbox],
|
26 |
+
outputs=[dropbox],
|
27 |
+
)
|
28 |
+
|
29 |
+
for plugin in os.listdir(os.path.join(now_dir, "tabs", "plugins", "installed")):
|
30 |
+
plugin_main = f"tabs.plugins.installed.{plugin}.plugin"
|
31 |
+
plugin_import = importlib.import_module(plugin_main)
|
32 |
+
|
33 |
+
with gr.TabItem(plugin):
|
34 |
+
plugin_import.applio_plugin()
|
tabs/plugins/plugins_core.py
ADDED
@@ -0,0 +1,102 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import os, sys, shutil
|
2 |
+
import json
|
3 |
+
import gradio as gr
|
4 |
+
import zipfile
|
5 |
+
import subprocess
|
6 |
+
|
7 |
+
from assets.i18n.i18n import I18nAuto
|
8 |
+
|
9 |
+
i18n = I18nAuto()
|
10 |
+
|
11 |
+
now_dir = os.getcwd()
|
12 |
+
sys.path.append(now_dir)
|
13 |
+
|
14 |
+
plugins_path = os.path.join(now_dir, "tabs", "plugins", "installed")
|
15 |
+
if not os.path.exists(plugins_path):
|
16 |
+
os.makedirs(plugins_path)
|
17 |
+
json_file_path = os.path.join(now_dir, "tabs", "plugins", "installed_list.json")
|
18 |
+
current_folders = os.listdir(plugins_path)
|
19 |
+
|
20 |
+
|
21 |
+
def get_existing_folders():
|
22 |
+
if os.path.exists(json_file_path):
|
23 |
+
with open(json_file_path, "r") as file:
|
24 |
+
return json.load(file)
|
25 |
+
else:
|
26 |
+
return []
|
27 |
+
|
28 |
+
|
29 |
+
def save_existing_folders(existing_folders):
|
30 |
+
with open(json_file_path, "w") as file:
|
31 |
+
json.dump(existing_folders, file)
|
32 |
+
|
33 |
+
|
34 |
+
def save_plugin_dropbox(dropbox):
|
35 |
+
if "zip" not in dropbox:
|
36 |
+
raise gr.Error(
|
37 |
+
message="The file you dropped is not a valid plugin.zip. Please try again."
|
38 |
+
)
|
39 |
+
else:
|
40 |
+
file_name = os.path.basename(dropbox)
|
41 |
+
folder_name = file_name.split(".zip")[0]
|
42 |
+
folder_path = os.path.join(plugins_path, folder_name)
|
43 |
+
zip_file_path = os.path.join(plugins_path, file_name)
|
44 |
+
|
45 |
+
if os.path.exists(folder_name):
|
46 |
+
os.remove(folder_name)
|
47 |
+
|
48 |
+
shutil.move(dropbox, os.path.join(plugins_path, file_name))
|
49 |
+
print("Proceeding with the extraction...")
|
50 |
+
|
51 |
+
with zipfile.ZipFile(zip_file_path, "r") as zip_ref:
|
52 |
+
zip_ref.extractall(plugins_path)
|
53 |
+
os.remove(zip_file_path)
|
54 |
+
|
55 |
+
if os.path.exists(os.path.join(folder_path, "requirements.txt")):
|
56 |
+
subprocess.run(
|
57 |
+
[
|
58 |
+
os.path.join("env", "python.exe"),
|
59 |
+
"-m",
|
60 |
+
"pip",
|
61 |
+
"install",
|
62 |
+
"-r",
|
63 |
+
os.path.join(folder_path, "requirements.txt"),
|
64 |
+
]
|
65 |
+
)
|
66 |
+
else:
|
67 |
+
print("No requirements.txt file found in the plugin folder.")
|
68 |
+
|
69 |
+
save_existing_folders(get_existing_folders() + [folder_name])
|
70 |
+
|
71 |
+
print(
|
72 |
+
f"{folder_name} plugin installed in {plugins_path}! Restart applio to see the changes."
|
73 |
+
)
|
74 |
+
gr.Info(
|
75 |
+
f"{folder_name} plugin installed in {plugins_path}! Restart applio to see the changes."
|
76 |
+
)
|
77 |
+
return None
|
78 |
+
|
79 |
+
|
80 |
+
def check_new_folders():
|
81 |
+
existing_folders = get_existing_folders()
|
82 |
+
new_folders = set(current_folders) - set(existing_folders)
|
83 |
+
if new_folders:
|
84 |
+
for new_folder in new_folders:
|
85 |
+
complete_path = os.path.join(plugins_path, new_folder)
|
86 |
+
print(f"New plugin {new_folder} found, installing it...")
|
87 |
+
|
88 |
+
if os.path.exists(os.path.join(complete_path, "requirements.txt")):
|
89 |
+
subprocess.run(
|
90 |
+
[
|
91 |
+
os.path.join("env", "python.exe"),
|
92 |
+
"-m",
|
93 |
+
"pip",
|
94 |
+
"install",
|
95 |
+
"-r",
|
96 |
+
os.path.join(complete_path, "requirements.txt"),
|
97 |
+
]
|
98 |
+
)
|
99 |
+
else:
|
100 |
+
print("No requirements.txt file found in the plugin folder.")
|
101 |
+
print("Plugins checked and installed! Restart applio to see the changes.")
|
102 |
+
save_existing_folders(current_folders)
|