Skip to content

Commit

Permalink
fix(gui): disable checkbox if CUDA is not available and show errors f…
Browse files Browse the repository at this point in the history
…or VC (#71)
  • Loading branch information
34j committed Mar 22, 2023
1 parent 6c6cbc6 commit 3fdd983
Showing 1 changed file with 32 additions and 8 deletions.
40 changes: 32 additions & 8 deletions src/so_vits_svc_fork/gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import PySimpleGUI as sg
import sounddevice as sd
import torch
from pebble import ProcessPool
from pebble import ProcessFuture, ProcessPool

from .__main__ import init_logger

Expand Down Expand Up @@ -360,7 +360,22 @@ def main():
frames["Presets"],
[
sg.Checkbox(
key="use_gpu", default=torch.cuda.is_available(), text="Use GPU"
key="use_gpu",
default=(
torch.cuda.is_available() or torch.backends.mps.is_available()
),
text="Use GPU"
+ (
" (not available; if your device has GPU, make sure you installed PyTorch with CUDA support)"
if not (
torch.cuda.is_available()
or torch.backends.mps.is_available()
)
else ""
),
disabled=not (
torch.cuda.is_available() or torch.backends.mps.is_available()
),
)
],
[
Expand Down Expand Up @@ -408,12 +423,11 @@ def apply_preset(name: str) -> None:
window["presets"].update(default_name)
del default_name
with ProcessPool(max_workers=1) as pool:
future = None
future: None | ProcessFuture = None
while True:
event, values = window.read()
event, values = window.read(100)
if event == sg.WIN_CLOSED:
break

if not event == sg.EVENT_TIMEOUT:
LOG.info(f"Event {event}, values {values}")
if event.endswith("_path"):
Expand All @@ -428,8 +442,7 @@ def apply_preset(name: str) -> None:
browser.update()
else:
LOG.warning(f"Browser {browser} is not a FileBrowse")

if event == "add_preset":
elif event == "add_preset":
presets = add_preset(
values["preset_name"], {key: values[key] for key in PRESET_KEYS}
)
Expand Down Expand Up @@ -469,7 +482,15 @@ def apply_preset(name: str) -> None:
pad_seconds=values["pad_seconds"],
absolute_thresh=values["absolute_thresh"],
chunk_seconds=values["chunk_seconds"],
device="cuda" if values["use_gpu"] else "cpu",
device="cpu"
if not values["use_gpu"]
else (
"cuda"
if torch.cuda.is_available()
else "mps"
if torch.backends.mps.is_available()
else "cpu"
),
)
if values["auto_play"]:
pool.schedule(play_audio, args=[output_path])
Expand Down Expand Up @@ -518,6 +539,9 @@ def apply_preset(name: str) -> None:
if future:
future.cancel()
future = None
if future is not None and future.done():
LOG.error(f"Error in realtime: {future.exception()}")
future = None
if future:
future.cancel()
window.close()

0 comments on commit 3fdd983

Please sign in to comment.