Spaces:
Sleeping
Sleeping
Upload 2 files
Browse files- Dockerfile +6 -0
- app.py +12 -1
Dockerfile
CHANGED
|
@@ -10,6 +10,9 @@ RUN apt-get update && apt-get install -y \
|
|
| 10 |
ffmpeg \
|
| 11 |
&& rm -rf /var/lib/apt/lists/*
|
| 12 |
|
|
|
|
|
|
|
|
|
|
| 13 |
# Copy requirements and install Python dependencies
|
| 14 |
COPY requirements.txt .
|
| 15 |
RUN pip install --no-cache-dir -r requirements.txt
|
|
@@ -23,6 +26,9 @@ EXPOSE 7860
|
|
| 23 |
# Set environment variables
|
| 24 |
ENV PYTHONUNBUFFERED=1
|
| 25 |
ENV PORT=7860
|
|
|
|
|
|
|
|
|
|
| 26 |
|
| 27 |
# Run the FastAPI application
|
| 28 |
CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860"]
|
|
|
|
| 10 |
ffmpeg \
|
| 11 |
&& rm -rf /var/lib/apt/lists/*
|
| 12 |
|
| 13 |
+
# Create cache directory with proper permissions
|
| 14 |
+
RUN mkdir -p /app/.cache && chmod 777 /app/.cache
|
| 15 |
+
|
| 16 |
# Copy requirements and install Python dependencies
|
| 17 |
COPY requirements.txt .
|
| 18 |
RUN pip install --no-cache-dir -r requirements.txt
|
|
|
|
| 26 |
# Set environment variables
|
| 27 |
ENV PYTHONUNBUFFERED=1
|
| 28 |
ENV PORT=7860
|
| 29 |
+
ENV HF_HOME=/app/.cache
|
| 30 |
+
ENV HF_DATASETS_CACHE=/app/.cache
|
| 31 |
+
ENV TRANSFORMERS_CACHE=/app/.cache
|
| 32 |
|
| 33 |
# Run the FastAPI application
|
| 34 |
CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860"]
|
app.py
CHANGED
|
@@ -31,11 +31,22 @@ async def lifespan(app: FastAPI):
|
|
| 31 |
try:
|
| 32 |
from sonics import HFAudioClassifier
|
| 33 |
print("π Loading Madverse Music AI model...")
|
| 34 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 35 |
model.eval()
|
| 36 |
print("β
Model loaded successfully!")
|
| 37 |
except Exception as e:
|
| 38 |
print(f"β Failed to load model: {e}")
|
|
|
|
|
|
|
| 39 |
raise
|
| 40 |
|
| 41 |
yield
|
|
|
|
| 31 |
try:
|
| 32 |
from sonics import HFAudioClassifier
|
| 33 |
print("π Loading Madverse Music AI model...")
|
| 34 |
+
|
| 35 |
+
# Set cache directory to a writable location
|
| 36 |
+
cache_dir = "/app/.cache" if os.path.exists("/app") else "./cache"
|
| 37 |
+
os.makedirs(cache_dir, exist_ok=True)
|
| 38 |
+
|
| 39 |
+
# Load model with explicit cache directory
|
| 40 |
+
model = HFAudioClassifier.from_pretrained(
|
| 41 |
+
"awsaf49/sonics-spectttra-alpha-120s",
|
| 42 |
+
cache_dir=cache_dir
|
| 43 |
+
)
|
| 44 |
model.eval()
|
| 45 |
print("β
Model loaded successfully!")
|
| 46 |
except Exception as e:
|
| 47 |
print(f"β Failed to load model: {e}")
|
| 48 |
+
import traceback
|
| 49 |
+
traceback.print_exc()
|
| 50 |
raise
|
| 51 |
|
| 52 |
yield
|