Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -9,16 +9,24 @@ import psutil
|
|
9 |
|
10 |
app = FastAPI()
|
11 |
start_time = time.time()
|
|
|
12 |
|
|
|
|
|
13 |
# Load model during startup
|
14 |
@app.on_event("startup")
|
15 |
def load_model():
|
16 |
try:
|
17 |
-
|
18 |
-
|
|
|
|
|
|
|
|
|
|
|
19 |
except Exception as e:
|
20 |
-
print(f"Error loading model: {e}")
|
21 |
-
raise
|
22 |
|
23 |
def format_time(seconds: float) -> str:
|
24 |
"""Convert seconds to SRT time format"""
|
|
|
9 |
|
10 |
app = FastAPI()
|
11 |
start_time = time.time()
|
12 |
+
MODEL_CACHE_DIR = "./model_cache" # Use writable directory
|
13 |
|
14 |
+
# Create cache directory if not exists
|
15 |
+
os.makedirs(MODEL_CACHE_DIR, exist_ok=True)
|
16 |
# Load model during startup
|
17 |
@app.on_event("startup")
|
18 |
def load_model():
|
19 |
try:
|
20 |
+
# Load model directly into memory with explicit cache dir
|
21 |
+
app.state.model = whisper.load_model(
|
22 |
+
"large",
|
23 |
+
download_root=MODEL_CACHE_DIR,
|
24 |
+
in_memory=True # Force in-memory loading
|
25 |
+
)
|
26 |
+
print(f"Model loaded successfully on device: {app.state.model.device}")
|
27 |
except Exception as e:
|
28 |
+
print(f"Error loading model: {str(e)}")
|
29 |
+
raise RuntimeError("Failed to load Whisper model")
|
30 |
|
31 |
def format_time(seconds: float) -> str:
|
32 |
"""Convert seconds to SRT time format"""
|