Spaces:
Running
Running
Upload 5 files
Browse files- .dockerignore +48 -0
- Dockerfile +23 -17
- docker-compose.yml +22 -0
- requirements.txt +10 -12
- server.py +3 -1
.dockerignore
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Python
|
| 2 |
+
__pycache__/
|
| 3 |
+
*.py[cod]
|
| 4 |
+
*$py.class
|
| 5 |
+
*.so
|
| 6 |
+
.Python
|
| 7 |
+
build/
|
| 8 |
+
develop-eggs/
|
| 9 |
+
dist/
|
| 10 |
+
downloads/
|
| 11 |
+
eggs/
|
| 12 |
+
.eggs/
|
| 13 |
+
lib64/
|
| 14 |
+
parts/
|
| 15 |
+
sdist/
|
| 16 |
+
var/
|
| 17 |
+
wheels/
|
| 18 |
+
*.egg-info/
|
| 19 |
+
.installed.cfg
|
| 20 |
+
*.egg
|
| 21 |
+
|
| 22 |
+
# Virtual Environment
|
| 23 |
+
venv/
|
| 24 |
+
ENV/
|
| 25 |
+
|
| 26 |
+
# IDE
|
| 27 |
+
.vscode/
|
| 28 |
+
.idea/
|
| 29 |
+
*.swp
|
| 30 |
+
*.swo
|
| 31 |
+
|
| 32 |
+
# Environment variables
|
| 33 |
+
.env
|
| 34 |
+
|
| 35 |
+
# Logs
|
| 36 |
+
*.log
|
| 37 |
+
|
| 38 |
+
# Local development files
|
| 39 |
+
.local/
|
| 40 |
+
|
| 41 |
+
# OS generated files
|
| 42 |
+
.DS_Store
|
| 43 |
+
.DS_Store?
|
| 44 |
+
._*
|
| 45 |
+
.Spotlight-V100
|
| 46 |
+
.Trashes
|
| 47 |
+
ehthumbs.db
|
| 48 |
+
Thumbs.db
|
Dockerfile
CHANGED
|
@@ -1,31 +1,37 @@
|
|
|
|
|
| 1 |
FROM python:3.11-slim
|
| 2 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3 |
WORKDIR /app
|
| 4 |
|
| 5 |
-
# Install system dependencies
|
| 6 |
-
RUN apt-get update && apt-get install -y \
|
| 7 |
-
|
| 8 |
-
|
| 9 |
&& rm -rf /var/lib/apt/lists/*
|
| 10 |
|
| 11 |
-
# Copy requirements first
|
| 12 |
COPY requirements.txt .
|
| 13 |
-
RUN pip install --no-cache-dir -r requirements.txt
|
| 14 |
-
|
| 15 |
-
# Copy application code
|
| 16 |
-
COPY . .
|
| 17 |
|
| 18 |
-
#
|
| 19 |
-
RUN
|
| 20 |
|
| 21 |
-
# Create non-root user
|
| 22 |
-
RUN
|
|
|
|
| 23 |
USER appuser
|
| 24 |
|
| 25 |
-
#
|
| 26 |
-
|
| 27 |
-
CMD curl -f http://localhost:7860/health || exit 1
|
| 28 |
|
|
|
|
| 29 |
EXPOSE 7860
|
| 30 |
|
| 31 |
-
|
|
|
|
|
|
| 1 |
+
# Use an official Python runtime as a parent image
|
| 2 |
FROM python:3.11-slim
|
| 3 |
|
| 4 |
+
# Set environment variables
|
| 5 |
+
ENV PYTHONDONTWRITEBYTECODE 1
|
| 6 |
+
ENV PYTHONUNBUFFERED 1
|
| 7 |
+
ENV FLASK_APP=server.py
|
| 8 |
+
ENV FLASK_ENV=production
|
| 9 |
+
|
| 10 |
+
# Set the working directory in the container
|
| 11 |
WORKDIR /app
|
| 12 |
|
| 13 |
+
# Install system dependencies required for some Python packages
|
| 14 |
+
RUN apt-get update && apt-get install -y --no-install-recommends \
|
| 15 |
+
gcc \
|
| 16 |
+
python3-dev \
|
| 17 |
&& rm -rf /var/lib/apt/lists/*
|
| 18 |
|
| 19 |
+
# Copy requirements first to leverage Docker cache
|
| 20 |
COPY requirements.txt .
|
|
|
|
|
|
|
|
|
|
|
|
|
| 21 |
|
| 22 |
+
# Install Python dependencies
|
| 23 |
+
RUN pip install --no-cache-dir -r requirements.txt gunicorn==21.2.0
|
| 24 |
|
| 25 |
+
# Create a non-root user and switch to it
|
| 26 |
+
RUN groupadd -r appuser && useradd -r -g appuser appuser
|
| 27 |
+
RUN chown -R appuser:appuser /app
|
| 28 |
USER appuser
|
| 29 |
|
| 30 |
+
# Copy the rest of the application
|
| 31 |
+
COPY --chown=appuser:appuser . .
|
|
|
|
| 32 |
|
| 33 |
+
# Expose the port the app runs on
|
| 34 |
EXPOSE 7860
|
| 35 |
|
| 36 |
+
# Command to run the application
|
| 37 |
+
CMD ["gunicorn", "--bind", "0.0.0.0:7860", "--workers", "4", "--threads", "2", "server:app"]
|
docker-compose.yml
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version: '3.8'
|
| 2 |
+
|
| 3 |
+
services:
|
| 4 |
+
web:
|
| 5 |
+
build: .
|
| 6 |
+
ports:
|
| 7 |
+
- "5000:5000"
|
| 8 |
+
environment:
|
| 9 |
+
- FLASK_ENV=production
|
| 10 |
+
# Add other environment variables from your .env file here
|
| 11 |
+
# - SUPABASE_URL=your_supabase_url
|
| 12 |
+
# - SUPABASE_KEY=your_supabase_key
|
| 13 |
+
# - OPENAI_API_KEY=your_openai_key
|
| 14 |
+
volumes:
|
| 15 |
+
- .:/app
|
| 16 |
+
restart: unless-stopped
|
| 17 |
+
healthcheck:
|
| 18 |
+
test: ["CMD", "curl", "-f", "http://localhost:5000"]
|
| 19 |
+
interval: 30s
|
| 20 |
+
timeout: 10s
|
| 21 |
+
retries: 3
|
| 22 |
+
start_period: 30s
|
requirements.txt
CHANGED
|
@@ -1,12 +1,10 @@
|
|
| 1 |
-
|
| 2 |
-
|
| 3 |
-
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
flask-cors
|
| 12 |
-
httpx
|
|
|
|
| 1 |
+
requests
|
| 2 |
+
beautifulsoup4
|
| 3 |
+
supabase
|
| 4 |
+
python-dotenv
|
| 5 |
+
openai
|
| 6 |
+
python-magic
|
| 7 |
+
python-magic-bin
|
| 8 |
+
flask
|
| 9 |
+
flask-cors
|
| 10 |
+
gunicorn
|
|
|
|
|
|
server.py
CHANGED
|
@@ -6,6 +6,7 @@ from conversation_manager import ConversationManager # Make sure this import is
|
|
| 6 |
import logging
|
| 7 |
import uuid
|
| 8 |
import os
|
|
|
|
| 9 |
|
| 10 |
# Configure logging
|
| 11 |
logging.basicConfig(level=logging.INFO)
|
|
@@ -13,6 +14,7 @@ logger = logging.getLogger(__name__)
|
|
| 13 |
|
| 14 |
# Initialize the Flask application
|
| 15 |
app = Flask(__name__)
|
|
|
|
| 16 |
|
| 17 |
# --- Initialize Core Services ---
|
| 18 |
# This setup assumes your .env file is correctly configured with Supabase credentials.
|
|
@@ -136,4 +138,4 @@ def clear_history():
|
|
| 136 |
# --- Main Execution ---
|
| 137 |
if __name__ == '__main__':
|
| 138 |
# Set debug=False for production
|
| 139 |
-
app.run(debug=
|
|
|
|
| 6 |
import logging
|
| 7 |
import uuid
|
| 8 |
import os
|
| 9 |
+
from flask_cors import CORS
|
| 10 |
|
| 11 |
# Configure logging
|
| 12 |
logging.basicConfig(level=logging.INFO)
|
|
|
|
| 14 |
|
| 15 |
# Initialize the Flask application
|
| 16 |
app = Flask(__name__)
|
| 17 |
+
CORS(app)
|
| 18 |
|
| 19 |
# --- Initialize Core Services ---
|
| 20 |
# This setup assumes your .env file is correctly configured with Supabase credentials.
|
|
|
|
| 138 |
# --- Main Execution ---
|
| 139 |
if __name__ == '__main__':
|
| 140 |
# Set debug=False for production
|
| 141 |
+
app.run(debug=False, port=7860)
|