Spaces:
Running
on
Zero
Running
on
Zero
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,3 +1,11 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import re
|
| 2 |
import gradio as gr
|
| 3 |
import numpy as np
|
|
@@ -10,7 +18,6 @@ from model.utils import (
|
|
| 10 |
get_tokenizer,
|
| 11 |
convert_char_to_pinyin,
|
| 12 |
)
|
| 13 |
-
|
| 14 |
from infer.utils_infer import (
|
| 15 |
load_vocoder,
|
| 16 |
load_model,
|
|
@@ -23,18 +30,11 @@ from transformers import pipeline
|
|
| 23 |
import click
|
| 24 |
import soundfile as sf
|
| 25 |
|
| 26 |
-
# Import
|
| 27 |
-
try:
|
| 28 |
-
import spaces
|
| 29 |
-
USING_SPACES = True
|
| 30 |
-
except ImportError:
|
| 31 |
-
USING_SPACES = False
|
| 32 |
-
|
| 33 |
-
# Import PyTorch and related libraries after 'spaces'
|
| 34 |
import torch
|
| 35 |
import torchaudio
|
| 36 |
|
| 37 |
-
# GPU decorator
|
| 38 |
def gpu_decorator(func):
|
| 39 |
if USING_SPACES:
|
| 40 |
return spaces.GPU(func)
|
|
|
|
| 1 |
+
# Import 'spaces' early to prevent CUDA initialization conflicts
|
| 2 |
+
try:
|
| 3 |
+
import spaces
|
| 4 |
+
USING_SPACES = True
|
| 5 |
+
except ImportError:
|
| 6 |
+
USING_SPACES = False
|
| 7 |
+
|
| 8 |
+
# Delay PyTorch and related imports until after 'spaces'
|
| 9 |
import re
|
| 10 |
import gradio as gr
|
| 11 |
import numpy as np
|
|
|
|
| 18 |
get_tokenizer,
|
| 19 |
convert_char_to_pinyin,
|
| 20 |
)
|
|
|
|
| 21 |
from infer.utils_infer import (
|
| 22 |
load_vocoder,
|
| 23 |
load_model,
|
|
|
|
| 30 |
import click
|
| 31 |
import soundfile as sf
|
| 32 |
|
| 33 |
+
# Import PyTorch and torchaudio after 'spaces'
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 34 |
import torch
|
| 35 |
import torchaudio
|
| 36 |
|
| 37 |
+
# GPU decorator for 'spaces'
|
| 38 |
def gpu_decorator(func):
|
| 39 |
if USING_SPACES:
|
| 40 |
return spaces.GPU(func)
|