Skip to content

Commit

Permalink
optimize updates (#357)
Browse files Browse the repository at this point in the history
* add "Attempt Update" button for external extensions

* skip reinstalling packages when pip_packages version is not changed.

* make default port 7770 and sync it to React UI

* check actual extension versions when displaying their tabs
  • Loading branch information
rsxdalv authored Aug 1, 2024
1 parent da99359 commit b23972c
Show file tree
Hide file tree
Showing 10 changed files with 80 additions and 37 deletions.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@ List of models: Bark, MusicGen + AudioGen, Tortoise, RVC, Vocos, Demucs, Seamles

## Changelog

Aug 1:
* Add "Attempt Update" button for external extensions.
* Skip reinstalling packages when pip_packages version is not changed.
* Synchronize Gradio Port with React UI.
* Change default Gradio port to 7770 from 7860.

July 31:
* Fix React UI's MusicGen after the Gradio changes.
* Add unload button to Whisper extension.
Expand Down
1 change: 1 addition & 0 deletions installer_scripts/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ output.log
.gpu
.major_version
.python_version
.pip_packages

# Diagnostic
diagnostic.txt
7 changes: 5 additions & 2 deletions installer_scripts/init_app.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,10 @@ const updateConda = async () => {
await $("conda update -y -n base -c defaults conda");
};

const DEBUG_ALWAYS_RETURN_UPDATED = process.env.FORCE_REINSTALL ? true : false;
const FORCE_REINSTALL = process.env.FORCE_REINSTALL ? true : false;
const DEBUG_ALWAYS_RETURN_UPDATED = FORCE_REINSTALL || process.env.DEBUG_ALWAYS_RETURN_UPDATED
? true
: false;

const syncRepo = async () => {
if (!fs.existsSync(".git")) {
Expand Down Expand Up @@ -62,7 +65,7 @@ async function main() {
// });
// })
// .listen(8080);
const version = "0.0.5";
const version = "0.0.6";
displayMessage("\n\nStarting init app (version: " + version + ")...\n\n");

if (process.env.DEBUG_ALWAYS_RETURN_UPDATED) {
Expand Down
51 changes: 30 additions & 21 deletions installer_scripts/js/initializeApp.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,13 @@ const installDependencies = async (gpuchoice) => {
} else if (gpuchoice === "Apple M Series Chip" || gpuchoice === "CPU") {
await $(pytorchCPUInstall$);
} else if (gpuchoice === "AMD GPU (ROCM, Linux only, potentially broken)") {
displayMessage("ROCM is experimental and not well supported yet, installing...");
displayMessage(
"ROCM is experimental and not well supported yet, installing..."
);
displayMessage("Linux only!");
await $(`pip install torch==${torchVersion} torchvision==0.18.1 torchaudio==${torchVersion} --index-url https://download.pytorch.org/whl/rocm6.0`);
await $(
`pip install torch==${torchVersion} torchvision==0.18.1 torchaudio==${torchVersion} --index-url https://download.pytorch.org/whl/rocm6.0`
);
} else {
displayMessage("Unsupported or cancelled. Exiting...");
removeGPUChoice();
Expand Down Expand Up @@ -95,34 +99,34 @@ Select the device (GPU/CPU) you are using to run the application:

const gpuFile = "./installer_scripts/.gpu";
const majorVersionFile = "./installer_scripts/.major_version";
const pipPackagesFile = "./installer_scripts/.pip_packages";
const majorVersion = "2";

const saveGPUChoice = (gpuchoice) => {
fs.writeFileSync(gpuFile, gpuchoice.toString());
};
const versions = JSON.parse(fs.readFileSync("./installer_scripts/versions.json"));
const newPipPackagesVersion = String(versions.pip_packages);

const removeGPUChoice = () => {
if (fs.existsSync(gpuFile)) {
fs.unlinkSync(gpuFile);
}
};

const readGPUChoice = () => {
if (fs.existsSync(gpuFile)) {
return fs.readFileSync(gpuFile, "utf8");
const readGeneric = (file) => {
if (fs.existsSync(file)) {
return fs.readFileSync(file, "utf8");
}
return -1;
};

const readMajorVersion = () => {
if (fs.existsSync(majorVersionFile)) {
return fs.readFileSync(majorVersionFile, "utf8");
}
return -1;
const saveGeneric = (file, data) => {
fs.writeFileSync(file, data.toString());
};

const saveMajorVersion = (majorVersion) => {
fs.writeFileSync(majorVersionFile, majorVersion.toString());
const readMajorVersion = () => readGeneric(majorVersionFile);
const saveMajorVersion = (data) => saveGeneric(majorVersionFile, data);
const readPipPackagesVersion = () => readGeneric(pipPackagesFile);
const savePipPackagesVersion = (data) => saveGeneric(pipPackagesFile, data);
const readGPUChoice = () => readGeneric(gpuFile);
const saveGPUChoice = (data) => saveGeneric(gpuFile, data);

const removeGPUChoice = () => {
if (fs.existsSync(gpuFile)) {
fs.unlinkSync(gpuFile);
}
};

const dry_run_flag = DEBUG_DRY_RUN ? "--dry-run " : "";
Expand All @@ -140,6 +144,10 @@ function tryInstall(requirements, name = "") {
}

async function updateDependencies(optional = true) {
if (readPipPackagesVersion() === newPipPackagesVersion) {
displayMessage("Dependencies are already up to date, skipping pip installs...");
return;
}
if (optional) {
if (
(await menu(
Expand Down Expand Up @@ -167,6 +175,7 @@ async function updateDependencies(optional = true) {
tryInstall("-r requirements_stable_audio.txt", "Stable Audio");
// reinstall hydra-core==1.3.2 because of fairseq
tryInstall("hydra-core==1.3.2", "hydra-core fix due to fairseq");
savePipPackagesVersion(newPipPackagesVersion);
}

const checkIfTorchInstalled = async () => {
Expand Down
6 changes: 6 additions & 0 deletions installer_scripts/versions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"version": "0.0.2",
"pip_packages": 2,
"npm_packages": 1,
"react_ui": 1
}
2 changes: 1 addition & 1 deletion react-ui/src/pages/api/gradio/[name].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export default async function handler(
res.status(200).json(result);
}

const defaultBackend = process.env.GRADIO_BACKEND || "http://127.0.0.1:7860/";
const defaultBackend = process.env.GRADIO_BACKEND || process.env.GRADIO_BACKEND_AUTOMATIC || "http://127.0.0.1:7860/";
const getClient = () => client(defaultBackend, {});

type GradioChoices = {
Expand Down
9 changes: 8 additions & 1 deletion server.py
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,14 @@ def start_server():
import subprocess
import webbrowser

subprocess.Popen("npm start --prefix react-ui", shell=True)
subprocess.Popen(
"npm start --prefix react-ui",
env={
**os.environ,
"GRADIO_BACKEND_AUTOMATIC": f"http://127.0.0.1:{gradio_interface_options['server_port']}",
},
shell=True,
)
if gradio_interface_options["inbrowser"]:
webbrowser.open("http://localhost:3000")

Expand Down
2 changes: 1 addition & 1 deletion src/config/load_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"prevent_thread_lock": False,
"show_error": False,
"server_name": "0.0.0.0",
"server_port": None,
"server_port": 7770,
"show_tips": False,
"height": 500,
"width": "100%",
Expand Down
27 changes: 22 additions & 5 deletions src/extensions_loader/interface_extensions.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import json
import importlib
import importlib.util
from importlib.metadata import version

import gradio as gr

Expand All @@ -17,8 +18,24 @@ def _handle_package(package_name, title_name, requirements):
if check_if_package_installed(package_name):
try:
module = importlib.import_module(f"{package_name}.main")
if "builtin" in package_name:
package_version = "0.0.1"
else:
package_version = version(package_name)
main_tab = getattr(module, "extension__tts_generation_webui")
with gr.Tab(title_name + " Extension"):
with gr.Tab(f"{title_name} (v{package_version}) Extension"):
if "builtin" in package_name:
gr.Markdown(f"{title_name} Extension is up to date")
else:
if hasattr(module, "update_button"):
update_button = getattr(module, "update_button")
update_button()
else:
# universal update button
gr.Button("Attempt Update [May already be up to date]").click(
pip_install_wrapper(requirements, title_name),
outputs=[gr.HTML()],
)
main_tab()
except Exception as e:
generic_error_tab_advanced(
Expand Down Expand Up @@ -53,9 +70,8 @@ def handle_extension_class(extension_class):
x["extension_type"] == "interface"
and x["extension_class"] == extension_class
):
_handle_package(
x["package_name"], f"{x['name']} (v{x['version']})", x["requirements"]
)
# x["package_name"], f"{x['name']} (v{x['version']})", x["requirements"]
_handle_package(x["package_name"], x["name"], x["requirements"])


def extension_list_tab():
Expand All @@ -64,7 +80,8 @@ def extension_list_tab():
table_string = """| Title | Description |\n| --- | --- |\n"""
for x in extension_list_json:
table_string += (
f"| {x['name']} (v{x['version']}) "
# f"| {x['name']} (v{x['version']}) "
f"| {x['name']} "
+ f"| {x['description']} (website: {x['website']}) (extension_website: {x['extension_website']}) |\n"
)
gr.Markdown(table_string)
Expand Down
6 changes: 0 additions & 6 deletions version.json

This file was deleted.

0 comments on commit b23972c

Please sign in to comment.