Update app.py
Browse files
app.py
CHANGED
@@ -17,6 +17,11 @@ from huggingface_hub import login, hf_hub_download, scan_cache_dir
|
|
17 |
import speech_recognition as sr
|
18 |
import openai
|
19 |
|
|
|
|
|
|
|
|
|
|
|
20 |
# Set up environment variables and timeouts
|
21 |
os.environ["HF_HUB_DOWNLOAD_TIMEOUT"] = "300" # 5-minute timeout
|
22 |
|
@@ -37,9 +42,9 @@ if HF_TOKEN:
|
|
37 |
else:
|
38 |
print("⚠️ HF_TOKEN not found. Proceeding without login...")
|
39 |
|
40 |
-
# Set up device (GPU if available, otherwise CPU)
|
41 |
-
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
|
42 |
-
print(f"🔧 Using device: {device}")
|
43 |
|
44 |
# Initialize model variables
|
45 |
tts_model = None
|
@@ -83,7 +88,8 @@ def load_tts_model_with_retry(max_retries=3, retry_delay=5):
|
|
83 |
tts_repo_id,
|
84 |
trust_remote_code=True,
|
85 |
local_files_only=True,
|
86 |
-
device_map="auto"
|
|
|
87 |
)
|
88 |
tts_model_wrapper = TTSModelWrapper(tts_model)
|
89 |
print("TTS model loaded from cache successfully!")
|
@@ -101,6 +107,7 @@ def load_tts_model_with_retry(max_retries=3, retry_delay=5):
|
|
101 |
use_auth_token=HF_TOKEN,
|
102 |
low_cpu_mem_usage=True,
|
103 |
device_map="auto" # <-- Use device_map here as well
|
|
|
104 |
)
|
105 |
tts_model_wrapper = TTSModelWrapper(tts_model)
|
106 |
print(f"TTS model loaded successfully! Type: {type(tts_model)}")
|
@@ -398,7 +405,7 @@ def enhance_audio(audio_data):
|
|
398 |
|
399 |
return audio_data
|
400 |
|
401 |
-
def split_into_chunks(text, max_length=
|
402 |
"""Split text into smaller chunks based on punctuation and length"""
|
403 |
# First split by sentences
|
404 |
sentence_markers = ['.', '?', '!', ';', ':', '।', '॥']
|
|
|
17 |
import speech_recognition as sr
|
18 |
import openai
|
19 |
|
20 |
+
import torch
|
21 |
+
print("CUDA available:", torch.cuda.is_available())
|
22 |
+
print("CUDA device:", torch.cuda.current_device() if torch.cuda.is_available() else "None")
|
23 |
+
|
24 |
+
|
25 |
# Set up environment variables and timeouts
|
26 |
os.environ["HF_HUB_DOWNLOAD_TIMEOUT"] = "300" # 5-minute timeout
|
27 |
|
|
|
42 |
else:
|
43 |
print("⚠️ HF_TOKEN not found. Proceeding without login...")
|
44 |
|
45 |
+
# # Set up device (GPU if available, otherwise CPU)
|
46 |
+
# device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
|
47 |
+
# print(f"🔧 Using device: {device}")
|
48 |
|
49 |
# Initialize model variables
|
50 |
tts_model = None
|
|
|
88 |
tts_repo_id,
|
89 |
trust_remote_code=True,
|
90 |
local_files_only=True,
|
91 |
+
device_map="auto"
|
92 |
+
torch_dtype=torch.float16
|
93 |
)
|
94 |
tts_model_wrapper = TTSModelWrapper(tts_model)
|
95 |
print("TTS model loaded from cache successfully!")
|
|
|
107 |
use_auth_token=HF_TOKEN,
|
108 |
low_cpu_mem_usage=True,
|
109 |
device_map="auto" # <-- Use device_map here as well
|
110 |
+
|
111 |
)
|
112 |
tts_model_wrapper = TTSModelWrapper(tts_model)
|
113 |
print(f"TTS model loaded successfully! Type: {type(tts_model)}")
|
|
|
405 |
|
406 |
return audio_data
|
407 |
|
408 |
+
def split_into_chunks(text, max_length=8):
|
409 |
"""Split text into smaller chunks based on punctuation and length"""
|
410 |
# First split by sentences
|
411 |
sentence_markers = ['.', '?', '!', ';', ':', '।', '॥']
|