Skip to content

Commit

Permalink
feat(gui): remember last directory (misc)
Browse files Browse the repository at this point in the history
  • Loading branch information
34j committed Mar 18, 2023
1 parent 3d298df commit 92558da
Showing 1 changed file with 33 additions and 9 deletions.
42 changes: 33 additions & 9 deletions src/so_vits_svc_fork/gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,35 +35,49 @@ def main():
sg.Push(),
sg.InputText(
key="model_path",
default_text=model_candidates[-1].as_posix()
default_text=model_candidates[-1].absolute().as_posix()
if model_candidates
else "",
),
sg.FileBrowse(
initial_folder="./logs/44k/"
initial_folder=Path("./logs/44k/").absolute
if Path("./logs/44k/").exists()
else "."
else Path(".").absolute().as_posix(),
key="model_path_browse",
file_types=(("PyTorch", "*.pth"),),
),
],
[
sg.Text("Config path"),
sg.Push(),
sg.InputText(
key="config_path",
default_text="./configs/44k/config.json",
default_text=Path("./configs/44k/config.json")
.absolute()
.as_posix()
if Path("./configs/44k/config.json").exists()
else "",
enable_events=True,
),
sg.FileBrowse(
initial_folder="./configs/44k/"
initial_folder=Path("./configs/44k/").as_posix()
if Path("./configs/44k/").exists()
else "."
else Path(".").absolute().as_posix(),
key="config_path_browse",
file_types=(("JSON", "*.json"),),
),
],
[
sg.Text("Cluster model path"),
sg.Push(),
sg.InputText(key="cluster_model_path"),
sg.FileBrowse(),
sg.FileBrowse(
initial_folder="./logs/44k/"
if Path("./logs/44k/").exists()
else ".",
key="cluster_model_path_browse",
file_types=(("PyTorch", "*.pth"),),
),
],
],
)
Expand Down Expand Up @@ -234,7 +248,8 @@ def main():
def update_combo() -> None:
from . import utils

if Path(values["config_path"]).exists():
config_path = Path(values["config_path"])
if config_path.exists() and config_path.is_file():
hp = utils.get_hparams_from_file(values["config_path"])
LOG.info(f"Loaded config from {values['config_path']}")
window["speaker"].update(
Expand All @@ -245,7 +260,16 @@ def update_combo() -> None:
LOG.info(f"Event {event}, values {values}")
if values["speaker"] == "":
update_combo()

if event.endswith("_path"):
browser = window[f"{event}_browse"]
if isinstance(browser, sg.Button):
LOG.info(
f"Updating browser {browser} to {Path(values[event]).parent}"
)
browser.InitialFolder = Path(values[event]).parent
browser.update()
else:
LOG.warning(f"Browser {browser} is not a FileBrowse")
if event == "config_path":
update_combo()
elif event == "infer":
Expand Down

0 comments on commit 92558da

Please sign in to comment.