Spaces:
Sleeping
Sleeping
Samarth Naik commited on
Commit ·
91e5e21
1
Parent(s): c7281c7
Optimize: Switch to Gunicorn WSGI server and uv for faster builds
Browse files- Dockerfile +6 -2
- app.py +4 -1
- requirements.txt +3 -2
Dockerfile
CHANGED
|
@@ -2,11 +2,15 @@ FROM python:3.9-slim
|
|
| 2 |
|
| 3 |
WORKDIR /app
|
| 4 |
|
|
|
|
|
|
|
|
|
|
| 5 |
COPY requirements.txt .
|
| 6 |
-
RUN pip install -
|
| 7 |
|
| 8 |
COPY . .
|
| 9 |
|
| 10 |
EXPOSE 5000
|
| 11 |
|
| 12 |
-
|
|
|
|
|
|
| 2 |
|
| 3 |
WORKDIR /app
|
| 4 |
|
| 5 |
+
# Install uv
|
| 6 |
+
RUN pip install uv
|
| 7 |
+
|
| 8 |
COPY requirements.txt .
|
| 9 |
+
RUN uv pip install -r requirements.txt --system
|
| 10 |
|
| 11 |
COPY . .
|
| 12 |
|
| 13 |
EXPOSE 5000
|
| 14 |
|
| 15 |
+
# Use gunicorn for production - 4 workers for better concurrency
|
| 16 |
+
CMD ["gunicorn", "--bind", "0.0.0.0:5000", "--workers", "4", "--timeout", "300", "--access-logfile", "-", "--error-logfile", "-", "app:app"]
|
app.py
CHANGED
|
@@ -195,4 +195,7 @@ def get_models():
|
|
| 195 |
})
|
| 196 |
|
| 197 |
if __name__ == '__main__':
|
| 198 |
-
|
|
|
|
|
|
|
|
|
|
|
|
| 195 |
})
|
| 196 |
|
| 197 |
if __name__ == '__main__':
|
| 198 |
+
# Use gunicorn in production, this is just for local development
|
| 199 |
+
import os
|
| 200 |
+
port = int(os.environ.get('PORT', 5000))
|
| 201 |
+
app.run(host='0.0.0.0', port=port, debug=False, threaded=True)
|
requirements.txt
CHANGED
|
@@ -6,6 +6,7 @@ tensorflow
|
|
| 6 |
lightgbm
|
| 7 |
xgboost
|
| 8 |
flask
|
|
|
|
|
|
|
| 9 |
python-dotenv
|
| 10 |
-
supabase
|
| 11 |
-
flask-cors
|
|
|
|
| 6 |
lightgbm
|
| 7 |
xgboost
|
| 8 |
flask
|
| 9 |
+
flask-cors
|
| 10 |
+
gunicorn
|
| 11 |
python-dotenv
|
| 12 |
+
supabase
|
|
|