Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -5,9 +5,11 @@ from TTS.api import TTS
|
|
5 |
import os
|
6 |
import subprocess
|
7 |
|
8 |
-
#
|
9 |
-
device = "
|
10 |
-
|
|
|
|
|
11 |
|
12 |
# Hugging Face LLM Client (DeepSeek R1 7B)
|
13 |
client = InferenceClient("deepseek-ai/deepseek-r1-7b")
|
@@ -16,13 +18,13 @@ client = InferenceClient("deepseek-ai/deepseek-r1-7b")
|
|
16 |
RVC_MODEL_PATH = "zeldabotw.pth"
|
17 |
RVC_INDEX_PATH = "zeldabotw.index"
|
18 |
|
19 |
-
# Function to call RVC for voice conversion
|
20 |
def convert_voice(input_wav, output_wav):
|
21 |
-
"""Converts input TTS audio to ZeldaBotW voice using RVC."""
|
22 |
if not os.path.exists(RVC_MODEL_PATH) or not os.path.exists(RVC_INDEX_PATH):
|
23 |
raise FileNotFoundError("RVC model files not found! Ensure zeldabotw.pth and zeldabotw.index are in the same directory.")
|
24 |
|
25 |
-
command = f"python infer_rvc.py --input {input_wav} --output {output_wav} --model {RVC_MODEL_PATH} --index {RVC_INDEX_PATH} --pitch_shift 0"
|
26 |
|
27 |
process = subprocess.run(command, shell=True, capture_output=True, text=True)
|
28 |
if process.returncode != 0:
|
@@ -46,11 +48,11 @@ def respond(message, history, system_message, max_tokens, temperature, top_p):
|
|
46 |
response += token
|
47 |
yield response, None, None # Text first
|
48 |
|
49 |
-
# Generate Speech from Text
|
50 |
tts_audio_path = "tts_output.wav"
|
51 |
tts_model.tts_to_file(text=response, file_path=tts_audio_path)
|
52 |
|
53 |
-
# Convert TTS output to ZeldaBotW voice
|
54 |
rvc_audio_path = "rvc_output.wav"
|
55 |
rvc_converted_path = convert_voice(tts_audio_path, rvc_audio_path)
|
56 |
|
@@ -58,7 +60,7 @@ def respond(message, history, system_message, max_tokens, temperature, top_p):
|
|
58 |
|
59 |
# Gradio UI
|
60 |
with gr.Blocks() as demo:
|
61 |
-
gr.Markdown("## DeepSeek R1 7B Chatbot with ZeldaBotW Voice")
|
62 |
|
63 |
chatbot = gr.Chatbot()
|
64 |
msg = gr.Textbox(label="User Input")
|
|
|
5 |
import os
|
6 |
import subprocess
|
7 |
|
8 |
+
# Force CPU usage
|
9 |
+
device = "cpu"
|
10 |
+
|
11 |
+
# Load TTS Model (Running on CPU)
|
12 |
+
tts_model = TTS("tts_models/en/ljspeech/tacotron2-DDC", gpu=False) # ✅ Ensures CPU-only execution
|
13 |
|
14 |
# Hugging Face LLM Client (DeepSeek R1 7B)
|
15 |
client = InferenceClient("deepseek-ai/deepseek-r1-7b")
|
|
|
18 |
RVC_MODEL_PATH = "zeldabotw.pth"
|
19 |
RVC_INDEX_PATH = "zeldabotw.index"
|
20 |
|
21 |
+
# Function to call RVC for voice conversion (CPU Mode)
|
22 |
def convert_voice(input_wav, output_wav):
|
23 |
+
"""Converts input TTS audio to ZeldaBotW voice using RVC (CPU Mode)."""
|
24 |
if not os.path.exists(RVC_MODEL_PATH) or not os.path.exists(RVC_INDEX_PATH):
|
25 |
raise FileNotFoundError("RVC model files not found! Ensure zeldabotw.pth and zeldabotw.index are in the same directory.")
|
26 |
|
27 |
+
command = f"python infer_rvc.py --input {input_wav} --output {output_wav} --model {RVC_MODEL_PATH} --index {RVC_INDEX_PATH} --pitch_shift 0 --device cpu"
|
28 |
|
29 |
process = subprocess.run(command, shell=True, capture_output=True, text=True)
|
30 |
if process.returncode != 0:
|
|
|
48 |
response += token
|
49 |
yield response, None, None # Text first
|
50 |
|
51 |
+
# Generate Speech from Text (CPU Mode)
|
52 |
tts_audio_path = "tts_output.wav"
|
53 |
tts_model.tts_to_file(text=response, file_path=tts_audio_path)
|
54 |
|
55 |
+
# Convert TTS output to ZeldaBotW voice (CPU Mode)
|
56 |
rvc_audio_path = "rvc_output.wav"
|
57 |
rvc_converted_path = convert_voice(tts_audio_path, rvc_audio_path)
|
58 |
|
|
|
60 |
|
61 |
# Gradio UI
|
62 |
with gr.Blocks() as demo:
|
63 |
+
gr.Markdown("## DeepSeek R1 7B Chatbot with ZeldaBotW Voice (CPU Mode)")
|
64 |
|
65 |
chatbot = gr.Chatbot()
|
66 |
msg = gr.Textbox(label="User Input")
|