Spaces:
Sleeping
Sleeping
Roger
commited on
Commit
·
3a938ac
1
Parent(s):
dd83b45
updated
Browse files- app.py +20 -24
- requirements.txt +1 -4
app.py
CHANGED
@@ -7,14 +7,7 @@ from scipy.io import wavfile
|
|
7 |
|
8 |
# Explicitly import Bark components
|
9 |
from bark import generate_audio, SAMPLE_RATE
|
10 |
-
from bark.generation import preload_models
|
11 |
-
|
12 |
-
# Add device detection
|
13 |
-
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
|
14 |
-
print("CUDA available:", torch.cuda.is_available())
|
15 |
-
print("CUDA device count:", torch.cuda.device_count())
|
16 |
-
if torch.cuda.is_available():
|
17 |
-
print("CUDA device name:", torch.cuda.get_device_name(0))
|
18 |
|
19 |
class VoiceCloningApp:
|
20 |
def __init__(self):
|
@@ -26,11 +19,17 @@ class VoiceCloningApp:
|
|
26 |
# Explicit model loading with error handling
|
27 |
try:
|
28 |
print("Attempting to load Bark models...")
|
29 |
-
|
30 |
-
|
|
|
31 |
except Exception as e:
|
32 |
print(f"Error loading Bark models: {e}")
|
33 |
-
|
|
|
|
|
|
|
|
|
|
|
34 |
|
35 |
def process_reference_audio(self, audio_data):
|
36 |
"""Simple audio processing"""
|
@@ -63,21 +62,11 @@ class VoiceCloningApp:
|
|
63 |
# Generate audio with explicit error handling
|
64 |
print(f"Generating speech for text: {text}")
|
65 |
|
66 |
-
#
|
67 |
-
semantic_tokens = generate_text_semantic(
|
68 |
-
text,
|
69 |
-
history_prompt=None,
|
70 |
-
temp=0.7,
|
71 |
-
min_eos_p=0.05,
|
72 |
-
device=device
|
73 |
-
)
|
74 |
-
|
75 |
-
# Generate audio from semantic tokens
|
76 |
audio_array = generate_audio(
|
77 |
-
|
78 |
history_prompt=None,
|
79 |
-
temp=0.7
|
80 |
-
device=device
|
81 |
)
|
82 |
|
83 |
# Save generated audio
|
@@ -89,9 +78,16 @@ class VoiceCloningApp:
|
|
89 |
|
90 |
except Exception as e:
|
91 |
print(f"Speech generation error: {e}")
|
|
|
|
|
|
|
92 |
return None, f"Error generating speech: {str(e)}"
|
93 |
|
94 |
def create_interface():
|
|
|
|
|
|
|
|
|
95 |
app = VoiceCloningApp()
|
96 |
|
97 |
# Use the most basic Gradio theme to avoid font issues
|
|
|
7 |
|
8 |
# Explicitly import Bark components
|
9 |
from bark import generate_audio, SAMPLE_RATE
|
10 |
+
from bark.generation import preload_models
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
11 |
|
12 |
class VoiceCloningApp:
|
13 |
def __init__(self):
|
|
|
19 |
# Explicit model loading with error handling
|
20 |
try:
|
21 |
print("Attempting to load Bark models...")
|
22 |
+
# Remove device argument
|
23 |
+
preload_models()
|
24 |
+
print("Bark models loaded successfully.")
|
25 |
except Exception as e:
|
26 |
print(f"Error loading Bark models: {e}")
|
27 |
+
# Log the full error for debugging
|
28 |
+
import traceback
|
29 |
+
traceback.print_exc()
|
30 |
+
|
31 |
+
# Provide a more informative error message
|
32 |
+
raise RuntimeError(f"Could not load Bark models. Error: {e}")
|
33 |
|
34 |
def process_reference_audio(self, audio_data):
|
35 |
"""Simple audio processing"""
|
|
|
62 |
# Generate audio with explicit error handling
|
63 |
print(f"Generating speech for text: {text}")
|
64 |
|
65 |
+
# Simplified audio generation
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
66 |
audio_array = generate_audio(
|
67 |
+
text,
|
68 |
history_prompt=None,
|
69 |
+
temp=0.7
|
|
|
70 |
)
|
71 |
|
72 |
# Save generated audio
|
|
|
78 |
|
79 |
except Exception as e:
|
80 |
print(f"Speech generation error: {e}")
|
81 |
+
# Log the full error for debugging
|
82 |
+
import traceback
|
83 |
+
traceback.print_exc()
|
84 |
return None, f"Error generating speech: {str(e)}"
|
85 |
|
86 |
def create_interface():
|
87 |
+
# Create working directory if it doesn't exist
|
88 |
+
working_dir = os.path.join(os.path.dirname(os.path.abspath(__file__)), "working_files")
|
89 |
+
os.makedirs(working_dir, exist_ok=True)
|
90 |
+
|
91 |
app = VoiceCloningApp()
|
92 |
|
93 |
# Use the most basic Gradio theme to avoid font issues
|
requirements.txt
CHANGED
@@ -2,9 +2,6 @@ gradio>=3.50.2
|
|
2 |
numpy
|
3 |
scipy
|
4 |
soundfile
|
5 |
-
torch
|
6 |
-
torchvision>=0.15.0+cu118
|
7 |
-
torchaudio>=2.0.0
|
8 |
transformers
|
9 |
git+https://github.com/suno-ai/bark.git
|
10 |
-
--extra-index-url https://download.pytorch.org/whl/cu118
|
|
|
2 |
numpy
|
3 |
scipy
|
4 |
soundfile
|
5 |
+
torch
|
|
|
|
|
6 |
transformers
|
7 |
git+https://github.com/suno-ai/bark.git
|
|