zsolnai commited on
Commit ·
d6a854b
1
Parent(s): 73707e8
Fix claude mistake v3
Browse files
app.py
CHANGED
|
@@ -2,6 +2,8 @@ import os
|
|
| 2 |
import tempfile
|
| 3 |
|
| 4 |
import gradio as gr
|
|
|
|
|
|
|
| 5 |
import torch
|
| 6 |
|
| 7 |
# --- Device Setup (Explicitly set to CPU) ---
|
|
@@ -23,6 +25,7 @@ chatbot_model.to(device)
|
|
| 23 |
from TTS.api import TTS
|
| 24 |
|
| 25 |
TTS_MODEL_NAME = "tts_models/en/ljspeech/tacotron2-DDC"
|
|
|
|
| 26 |
tts_model = TTS(model_name=TTS_MODEL_NAME, progress_bar=False)
|
| 27 |
|
| 28 |
|
|
@@ -66,10 +69,12 @@ def chat_with_bot(message, history, chat_history_ids=None):
|
|
| 66 |
# Encode the new user input and add end-of-sequence token
|
| 67 |
new_input_ids = chatbot_tokenizer.encode(
|
| 68 |
message + chatbot_tokenizer.eos_token, return_tensors="pt"
|
| 69 |
-
)
|
| 70 |
|
| 71 |
# Append the new user input tokens to the chat history
|
| 72 |
if chat_history_ids is not None:
|
|
|
|
|
|
|
| 73 |
bot_input_ids = torch.cat([chat_history_ids, new_input_ids], dim=-1)
|
| 74 |
else:
|
| 75 |
bot_input_ids = new_input_ids
|
|
@@ -109,7 +114,8 @@ custom_css = """
|
|
| 109 |
}
|
| 110 |
"""
|
| 111 |
|
| 112 |
-
|
|
|
|
| 113 |
gr.Markdown("# 🗣️ STT, TTS & Chat App (CPU Only)")
|
| 114 |
gr.Markdown(
|
| 115 |
"**NOTE:** This app is running on CPU-only hardware. Speech-to-Text (Whisper) is fast, but **Text-to-Speech (Coqui TTS) and Chat will be slow**."
|
|
@@ -185,4 +191,5 @@ with gr.Blocks(css=custom_css) as demo:
|
|
| 185 |
fn=text_to_speech, inputs=text_input, outputs=[audio_output, tts_status]
|
| 186 |
)
|
| 187 |
|
| 188 |
-
demo.launch()
|
|
|
|
|
|
| 2 |
import tempfile
|
| 3 |
|
| 4 |
import gradio as gr
|
| 5 |
+
import numpy as np
|
| 6 |
+
import soundfile as sf
|
| 7 |
import torch
|
| 8 |
|
| 9 |
# --- Device Setup (Explicitly set to CPU) ---
|
|
|
|
| 25 |
from TTS.api import TTS
|
| 26 |
|
| 27 |
TTS_MODEL_NAME = "tts_models/en/ljspeech/tacotron2-DDC"
|
| 28 |
+
# Initialize the TTS model on CPU
|
| 29 |
tts_model = TTS(model_name=TTS_MODEL_NAME, progress_bar=False)
|
| 30 |
|
| 31 |
|
|
|
|
| 69 |
# Encode the new user input and add end-of-sequence token
|
| 70 |
new_input_ids = chatbot_tokenizer.encode(
|
| 71 |
message + chatbot_tokenizer.eos_token, return_tensors="pt"
|
| 72 |
+
).to(device)
|
| 73 |
|
| 74 |
# Append the new user input tokens to the chat history
|
| 75 |
if chat_history_ids is not None:
|
| 76 |
+
# Move existing chat history IDs to the correct device
|
| 77 |
+
chat_history_ids = chat_history_ids.to(device)
|
| 78 |
bot_input_ids = torch.cat([chat_history_ids, new_input_ids], dim=-1)
|
| 79 |
else:
|
| 80 |
bot_input_ids = new_input_ids
|
|
|
|
| 114 |
}
|
| 115 |
"""
|
| 116 |
|
| 117 |
+
# CRITICAL FIX: Removed css argument from gr.Blocks()
|
| 118 |
+
with gr.Blocks() as demo:
|
| 119 |
gr.Markdown("# 🗣️ STT, TTS & Chat App (CPU Only)")
|
| 120 |
gr.Markdown(
|
| 121 |
"**NOTE:** This app is running on CPU-only hardware. Speech-to-Text (Whisper) is fast, but **Text-to-Speech (Coqui TTS) and Chat will be slow**."
|
|
|
|
| 191 |
fn=text_to_speech, inputs=text_input, outputs=[audio_output, tts_status]
|
| 192 |
)
|
| 193 |
|
| 194 |
+
# CRITICAL FIX: Passed css argument to demo.launch()
|
| 195 |
+
demo.launch(css=custom_css)
|