Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -17,7 +17,6 @@ app = FastAPI()
|
|
| 17 |
|
| 18 |
# --- Model Loading ---
|
| 19 |
# This section loads the AI model when the application starts.
|
| 20 |
-
# This is crucial for performance, so it only happens once.
|
| 21 |
MODEL_REPO = "cvssp/audioldm2"
|
| 22 |
pipeline = None
|
| 23 |
device = "cuda" if torch.cuda.is_available() else "cpu"
|
|
@@ -25,8 +24,13 @@ torch_dtype = torch.float16 if device == "cuda" else torch.float32
|
|
| 25 |
|
| 26 |
try:
|
| 27 |
logger.info(f"Attempting to load model '{MODEL_REPO}' on device: {device} with dtype: {torch_dtype}")
|
| 28 |
-
# Load the pre-trained AudioLDM2 pipeline
|
| 29 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 30 |
pipeline = pipeline.to(device)
|
| 31 |
logger.info("Model loaded successfully and moved to device.")
|
| 32 |
except Exception as e:
|
|
|
|
| 17 |
|
| 18 |
# --- Model Loading ---
|
| 19 |
# This section loads the AI model when the application starts.
|
|
|
|
| 20 |
MODEL_REPO = "cvssp/audioldm2"
|
| 21 |
pipeline = None
|
| 22 |
device = "cuda" if torch.cuda.is_available() else "cpu"
|
|
|
|
| 24 |
|
| 25 |
try:
|
| 26 |
logger.info(f"Attempting to load model '{MODEL_REPO}' on device: {device} with dtype: {torch_dtype}")
|
| 27 |
+
# Load the pre-trained AudioLDM2 pipeline, specifying a writable cache directory
|
| 28 |
+
# THIS IS THE FIX: Added cache_dir to point to a writable location
|
| 29 |
+
pipeline = AudioLDM2Pipeline.from_pretrained(
|
| 30 |
+
MODEL_REPO,
|
| 31 |
+
torch_dtype=torch_dtype,
|
| 32 |
+
cache_dir="/tmp/huggingface_cache"
|
| 33 |
+
)
|
| 34 |
pipeline = pipeline.to(device)
|
| 35 |
logger.info("Model loaded successfully and moved to device.")
|
| 36 |
except Exception as e:
|