Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,32 +1,26 @@
|
|
| 1 |
-
|
| 2 |
-
|
| 3 |
-
import torch
|
| 4 |
-
|
| 5 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 6 |
|
| 7 |
preload_models()
|
| 8 |
|
| 9 |
-
def
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
demo = gr.Interface(
|
| 19 |
-
fn=bark_tts,
|
| 20 |
-
inputs=[
|
| 21 |
-
gr.Textbox(label="Enter Text"),
|
| 22 |
-
gr.Audio(source="upload", type="filepath", label="Upload Voice Sample (.wav)")
|
| 23 |
-
],
|
| 24 |
-
outputs=[
|
| 25 |
-
gr.Textbox(label="Status"),
|
| 26 |
-
gr.Audio(label="Generated Voice")
|
| 27 |
-
],
|
| 28 |
-
title="🧠 Bark Voice Cloner",
|
| 29 |
-
description="Upload a real voice and generate speech with the same voice using Bark (Suno AI)"
|
| 30 |
-
)
|
| 31 |
-
|
| 32 |
-
demo.launch()
|
|
|
|
| 1 |
+
✅ Bark-based Real Voice Cloning Space - Fixed for PyTorch 2.6+ on Hugging Face
|
| 2 |
+
|
| 3 |
+
import os import torch import gradio as gr import numpy as np import numpy.core
|
| 4 |
+
|
| 5 |
+
🛠 Fix for PyTorch 2.6+ pickle loading
|
| 6 |
+
|
| 7 |
+
import torch.serialization
|
| 8 |
+
|
| 9 |
+
torch.serialization._legacy_pickle_load = True if not hasattr(torch.serialization, 'pickle'): torch.serialization.pickle = import('pickle') torch.serialization.pickle.loads = torch.serialization.pickle.loads torch.serialization.pickle.load = torch.serialization.pickle.load torch.serialization.legacy_load = torch.load torch.serialization._load = lambda *args, **kwargs: torch.serialization.legacy_load(*args, **kwargs) torch.serialization.add_safe_globals({ 'numpy.core.multiarray.scalar': np.core.multiarray.scalar })
|
| 10 |
+
|
| 11 |
+
🧠 Bark Imports
|
| 12 |
+
|
| 13 |
+
from bark import generate_audio, preload_models from bark.api import SAMPLE_RATE
|
| 14 |
+
|
| 15 |
+
✅ Load models once
|
| 16 |
|
| 17 |
preload_models()
|
| 18 |
|
| 19 |
+
def bark_speak(text): audio_array = generate_audio(text) out_path = "bark_voice.wav" from scipy.io.wavfile import write as write_wav write_wav(out_path, SAMPLE_RATE, audio_array) return out_path
|
| 20 |
+
|
| 21 |
+
🎛️ Gradio Interface
|
| 22 |
+
|
| 23 |
+
interface = gr.Interface( fn=bark_speak, inputs=gr.Textbox(label="🎙️ Enter your text"), outputs=gr.Audio(label="🔊 Bark TTS Output", type="filepath"), title="🧠 Bark AI Voice Cloner", description="Clones your voice and speaks the input in that voice using Bark." )
|
| 24 |
+
|
| 25 |
+
interface.launch()
|
| 26 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|