Update app.py
Browse files
app.py
CHANGED
|
@@ -398,18 +398,21 @@ def preprocess_audio(audio_path: str, target_sr: int = 16000) -> tuple:
|
|
| 398 |
if temp_mp3_path and os.path.exists(temp_mp3_path) and "temp" in temp_mp3_path:
|
| 399 |
os.unlink(temp_mp3_path)
|
| 400 |
|
| 401 |
-
# --- MODEL
|
| 402 |
-
#
|
| 403 |
models = {}
|
| 404 |
qa_system = {}
|
| 405 |
|
| 406 |
def load_models():
|
| 407 |
-
"""Load all models with caching."""
|
| 408 |
global models
|
| 409 |
|
| 410 |
if models: # Already loaded
|
|
|
|
| 411 |
return models
|
| 412 |
|
|
|
|
|
|
|
| 413 |
try:
|
| 414 |
print("Loading ASR model (IndicConformer)...")
|
| 415 |
asr_model_id = "ai4bharat/indic-conformer-600m-multilingual"
|
|
@@ -468,12 +471,15 @@ def load_models():
|
|
| 468 |
return models
|
| 469 |
|
| 470 |
def load_qa_system():
|
| 471 |
-
"""Load Q&A system with caching."""
|
| 472 |
global qa_system
|
| 473 |
|
| 474 |
if qa_system: # Already loaded
|
|
|
|
| 475 |
return qa_system
|
| 476 |
|
|
|
|
|
|
|
| 477 |
try:
|
| 478 |
# Load your Q&A dataset
|
| 479 |
if os.path.exists("cleaned_qa_dataset.xlsx"):
|
|
|
|
| 398 |
if temp_mp3_path and os.path.exists(temp_mp3_path) and "temp" in temp_mp3_path:
|
| 399 |
os.unlink(temp_mp3_path)
|
| 400 |
|
| 401 |
+
# --- GLOBAL MODEL STORAGE ---
|
| 402 |
+
# Global variables to store loaded models (acts as cache)
|
| 403 |
models = {}
|
| 404 |
qa_system = {}
|
| 405 |
|
| 406 |
def load_models():
|
| 407 |
+
"""Load all models with caching using global variables."""
|
| 408 |
global models
|
| 409 |
|
| 410 |
if models: # Already loaded
|
| 411 |
+
print("β
Models already loaded from cache")
|
| 412 |
return models
|
| 413 |
|
| 414 |
+
print("π Loading models for the first time...")
|
| 415 |
+
|
| 416 |
try:
|
| 417 |
print("Loading ASR model (IndicConformer)...")
|
| 418 |
asr_model_id = "ai4bharat/indic-conformer-600m-multilingual"
|
|
|
|
| 471 |
return models
|
| 472 |
|
| 473 |
def load_qa_system():
|
| 474 |
+
"""Load Q&A system with caching using global variables."""
|
| 475 |
global qa_system
|
| 476 |
|
| 477 |
if qa_system: # Already loaded
|
| 478 |
+
print("β
Q&A system already loaded from cache")
|
| 479 |
return qa_system
|
| 480 |
|
| 481 |
+
print("π Loading Q&A system for the first time...")
|
| 482 |
+
|
| 483 |
try:
|
| 484 |
# Load your Q&A dataset
|
| 485 |
if os.path.exists("cleaned_qa_dataset.xlsx"):
|