Spaces:
Configuration error
Configuration error
Upload 13 files
Browse files- Dockerfile +22 -3
- Dockerfile.simple +43 -0
- app.py +22 -0
- start.sh +64 -0
Dockerfile
CHANGED
|
@@ -3,6 +3,12 @@ FROM python:3.9-slim
|
|
| 3 |
# Set working directory
|
| 4 |
WORKDIR /app
|
| 5 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 6 |
# Install system dependencies
|
| 7 |
RUN apt-get update && apt-get install -y \
|
| 8 |
git \
|
|
@@ -24,8 +30,9 @@ RUN apt-get update && apt-get install -y \
|
|
| 24 |
# Copy requirements first to leverage Docker cache
|
| 25 |
COPY requirements.txt .
|
| 26 |
|
| 27 |
-
# Install dependencies
|
| 28 |
RUN pip install --no-cache-dir --upgrade pip setuptools wheel && \
|
|
|
|
| 29 |
pip install --no-cache-dir salesforce-lavis && \
|
| 30 |
pip install --no-cache-dir torch>=1.10.0 torchvision>=0.11.0 && \
|
| 31 |
pip install --no-cache-dir Flask==2.3.3 gunicorn==21.2.0 && \
|
|
@@ -39,13 +46,25 @@ RUN pip install --no-cache-dir --upgrade pip setuptools wheel && \
|
|
| 39 |
# Copy application code
|
| 40 |
COPY . .
|
| 41 |
|
|
|
|
|
|
|
|
|
|
| 42 |
# Create necessary directories
|
| 43 |
RUN mkdir -p static/css templates
|
| 44 |
|
| 45 |
-
# Set environment variables for Hugging Face Spaces
|
| 46 |
ENV PYTHONPATH=/app
|
| 47 |
ENV FLASK_APP=app.py
|
| 48 |
ENV FLASK_ENV=production
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 49 |
|
| 50 |
# Expose port for Hugging Face Spaces
|
| 51 |
EXPOSE 7860
|
|
@@ -55,4 +74,4 @@ HEALTHCHECK --interval=30s --timeout=30s --start-period=5s --retries=3 \
|
|
| 55 |
CMD curl -f http://localhost:7860/health || exit 1
|
| 56 |
|
| 57 |
# Command to run the application
|
| 58 |
-
CMD ["
|
|
|
|
| 3 |
# Set working directory
|
| 4 |
WORKDIR /app
|
| 5 |
|
| 6 |
+
# Create cache directories with proper permissions
|
| 7 |
+
RUN mkdir -p /.cache/huggingface/hub && \
|
| 8 |
+
chmod -R 777 /.cache/huggingface && \
|
| 9 |
+
mkdir -p /app/.cache && \
|
| 10 |
+
chmod -R 777 /app/.cache
|
| 11 |
+
|
| 12 |
# Install system dependencies
|
| 13 |
RUN apt-get update && apt-get install -y \
|
| 14 |
git \
|
|
|
|
| 30 |
# Copy requirements first to leverage Docker cache
|
| 31 |
COPY requirements.txt .
|
| 32 |
|
| 33 |
+
# Install dependencies with numpy compatibility fix
|
| 34 |
RUN pip install --no-cache-dir --upgrade pip setuptools wheel && \
|
| 35 |
+
pip install --no-cache-dir --force-reinstall --no-deps numpy==1.21.6 && \
|
| 36 |
pip install --no-cache-dir salesforce-lavis && \
|
| 37 |
pip install --no-cache-dir torch>=1.10.0 torchvision>=0.11.0 && \
|
| 38 |
pip install --no-cache-dir Flask==2.3.3 gunicorn==21.2.0 && \
|
|
|
|
| 46 |
# Copy application code
|
| 47 |
COPY . .
|
| 48 |
|
| 49 |
+
# Make startup script executable
|
| 50 |
+
RUN chmod +x start.sh
|
| 51 |
+
|
| 52 |
# Create necessary directories
|
| 53 |
RUN mkdir -p static/css templates
|
| 54 |
|
| 55 |
+
# Set environment variables for Hugging Face Spaces and caching
|
| 56 |
ENV PYTHONPATH=/app
|
| 57 |
ENV FLASK_APP=app.py
|
| 58 |
ENV FLASK_ENV=production
|
| 59 |
+
ENV TRANSFORMERS_CACHE=/app/.cache/transformers
|
| 60 |
+
ENV HF_HOME=/app/.cache/huggingface
|
| 61 |
+
ENV TORCH_HOME=/app/.cache/torch
|
| 62 |
+
ENV HF_DATASETS_CACHE=/app/.cache/datasets
|
| 63 |
+
ENV HUGGINGFACE_HUB_CACHE=/app/.cache/huggingface/hub
|
| 64 |
+
|
| 65 |
+
# Create additional cache directories
|
| 66 |
+
RUN mkdir -p /app/.cache/transformers /app/.cache/huggingface /app/.cache/torch /app/.cache/datasets && \
|
| 67 |
+
chmod -R 777 /app/.cache
|
| 68 |
|
| 69 |
# Expose port for Hugging Face Spaces
|
| 70 |
EXPOSE 7860
|
|
|
|
| 74 |
CMD curl -f http://localhost:7860/health || exit 1
|
| 75 |
|
| 76 |
# Command to run the application
|
| 77 |
+
CMD ["./start.sh"]
|
Dockerfile.simple
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
FROM python:3.9-slim
|
| 2 |
+
|
| 3 |
+
# Set working directory
|
| 4 |
+
WORKDIR /app
|
| 5 |
+
|
| 6 |
+
# Set environment variables first
|
| 7 |
+
ENV TRANSFORMERS_CACHE=/tmp/transformers
|
| 8 |
+
ENV HF_HOME=/tmp/huggingface
|
| 9 |
+
ENV TORCH_HOME=/tmp/torch
|
| 10 |
+
ENV HUGGINGFACE_HUB_CACHE=/tmp/huggingface/hub
|
| 11 |
+
ENV PYTHONPATH=/app
|
| 12 |
+
ENV FLASK_APP=app.py
|
| 13 |
+
ENV FLASK_ENV=production
|
| 14 |
+
|
| 15 |
+
# Install system dependencies
|
| 16 |
+
RUN apt-get update && apt-get install -y \
|
| 17 |
+
git curl wget build-essential \
|
| 18 |
+
libgl1-mesa-dev libglib2.0-0 \
|
| 19 |
+
libsm6 libxext6 libxrender-dev \
|
| 20 |
+
libgomp1 libgcc-s1 ffmpeg \
|
| 21 |
+
&& rm -rf /var/lib/apt/lists/*
|
| 22 |
+
|
| 23 |
+
# Create cache directories with proper permissions
|
| 24 |
+
RUN mkdir -p /tmp/transformers /tmp/huggingface /tmp/torch && \
|
| 25 |
+
chmod -R 777 /tmp/
|
| 26 |
+
|
| 27 |
+
# Copy application files
|
| 28 |
+
COPY . .
|
| 29 |
+
|
| 30 |
+
# Install minimal dependencies only
|
| 31 |
+
RUN pip install --no-cache-dir --upgrade pip && \
|
| 32 |
+
pip install Flask==2.3.3 pillow>=10.0.0 && \
|
| 33 |
+
pip install requests>=2.31.0 loguru
|
| 34 |
+
|
| 35 |
+
# Expose port
|
| 36 |
+
EXPOSE 7860
|
| 37 |
+
|
| 38 |
+
# Simple health check
|
| 39 |
+
HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 \
|
| 40 |
+
CMD curl -f http://localhost:7860/health || exit 1
|
| 41 |
+
|
| 42 |
+
# Run with simple python command
|
| 43 |
+
CMD ["python", "app.py"]
|
app.py
CHANGED
|
@@ -1,5 +1,17 @@
|
|
| 1 |
import os
|
| 2 |
import io
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3 |
import torch
|
| 4 |
from flask import Flask, render_template, request, jsonify, url_for
|
| 5 |
from PIL import Image
|
|
@@ -8,13 +20,23 @@ import logging
|
|
| 8 |
|
| 9 |
# Safe import with error handling
|
| 10 |
try:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 11 |
from transformers import AutoTokenizer
|
| 12 |
from blip2_vicuna_instruct import Blip2VicunaInstruct
|
| 13 |
MODEL_AVAILABLE = True
|
|
|
|
| 14 |
except ImportError as e:
|
| 15 |
logging.error(f"Model import failed: {e}")
|
| 16 |
MODEL_AVAILABLE = False
|
| 17 |
Blip2VicunaInstruct = None
|
|
|
|
|
|
|
|
|
|
|
|
|
| 18 |
|
| 19 |
app = Flask(__name__)
|
| 20 |
app.config['MAX_CONTENT_LENGTH'] = 16 * 1024 * 1024 # 16MB max file size
|
|
|
|
| 1 |
import os
|
| 2 |
import io
|
| 3 |
+
import sys
|
| 4 |
+
|
| 5 |
+
# Set cache directories before importing any ML libraries
|
| 6 |
+
os.environ['TRANSFORMERS_CACHE'] = os.environ.get('TRANSFORMERS_CACHE', '/app/.cache/transformers')
|
| 7 |
+
os.environ['HF_HOME'] = os.environ.get('HF_HOME', '/app/.cache/huggingface')
|
| 8 |
+
os.environ['TORCH_HOME'] = os.environ.get('TORCH_HOME', '/app/.cache/torch')
|
| 9 |
+
os.environ['HF_DATASETS_CACHE'] = os.environ.get('HF_DATASETS_CACHE', '/app/.cache/datasets')
|
| 10 |
+
|
| 11 |
+
# Create cache directories if they don't exist
|
| 12 |
+
for cache_dir in ['/app/.cache/transformers', '/app/.cache/huggingface', '/app/.cache/torch', '/app/.cache/datasets']:
|
| 13 |
+
os.makedirs(cache_dir, exist_ok=True)
|
| 14 |
+
|
| 15 |
import torch
|
| 16 |
from flask import Flask, render_template, request, jsonify, url_for
|
| 17 |
from PIL import Image
|
|
|
|
| 20 |
|
| 21 |
# Safe import with error handling
|
| 22 |
try:
|
| 23 |
+
import numpy as np
|
| 24 |
+
# Check numpy version compatibility
|
| 25 |
+
numpy_version = np.__version__
|
| 26 |
+
logging.info(f"NumPy version: {numpy_version}")
|
| 27 |
+
|
| 28 |
from transformers import AutoTokenizer
|
| 29 |
from blip2_vicuna_instruct import Blip2VicunaInstruct
|
| 30 |
MODEL_AVAILABLE = True
|
| 31 |
+
logging.info("All imports successful")
|
| 32 |
except ImportError as e:
|
| 33 |
logging.error(f"Model import failed: {e}")
|
| 34 |
MODEL_AVAILABLE = False
|
| 35 |
Blip2VicunaInstruct = None
|
| 36 |
+
except Exception as e:
|
| 37 |
+
logging.error(f"Unexpected error during import: {e}")
|
| 38 |
+
MODEL_AVAILABLE = False
|
| 39 |
+
Blip2VicunaInstruct = None
|
| 40 |
|
| 41 |
app = Flask(__name__)
|
| 42 |
app.config['MAX_CONTENT_LENGTH'] = 16 * 1024 * 1024 # 16MB max file size
|
start.sh
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/bin/bash
|
| 2 |
+
set -e
|
| 3 |
+
|
| 4 |
+
echo "🚀 Starting EmoVIT application..."
|
| 5 |
+
|
| 6 |
+
# Create and set permissions for cache directories
|
| 7 |
+
echo "📁 Setting up cache directories..."
|
| 8 |
+
mkdir -p /.cache/huggingface/hub
|
| 9 |
+
mkdir -p /app/.cache/transformers
|
| 10 |
+
mkdir -p /app/.cache/huggingface
|
| 11 |
+
mkdir -p /app/.cache/torch
|
| 12 |
+
mkdir -p /app/.cache/datasets
|
| 13 |
+
|
| 14 |
+
# Set permissions
|
| 15 |
+
chmod -R 777 /.cache/ 2>/dev/null || true
|
| 16 |
+
chmod -R 777 /app/.cache/ 2>/dev/null || true
|
| 17 |
+
|
| 18 |
+
# Set environment variables
|
| 19 |
+
export TRANSFORMERS_CACHE=${TRANSFORMERS_CACHE:-/app/.cache/transformers}
|
| 20 |
+
export HF_HOME=${HF_HOME:-/app/.cache/huggingface}
|
| 21 |
+
export TORCH_HOME=${TORCH_HOME:-/app/.cache/torch}
|
| 22 |
+
export HF_DATASETS_CACHE=${HF_DATASETS_CACHE:-/app/.cache/datasets}
|
| 23 |
+
export HUGGINGFACE_HUB_CACHE=${HUGGINGFACE_HUB_CACHE:-/app/.cache/huggingface/hub}
|
| 24 |
+
|
| 25 |
+
echo "✅ Cache directories set up"
|
| 26 |
+
echo "🔧 Environment variables:"
|
| 27 |
+
echo " TRANSFORMERS_CACHE=$TRANSFORMERS_CACHE"
|
| 28 |
+
echo " HF_HOME=$HF_HOME"
|
| 29 |
+
echo " TORCH_HOME=$TORCH_HOME"
|
| 30 |
+
|
| 31 |
+
# Test dependencies
|
| 32 |
+
echo "🔍 Testing dependencies..."
|
| 33 |
+
python3 -c "
|
| 34 |
+
import sys
|
| 35 |
+
import warnings
|
| 36 |
+
warnings.filterwarnings('ignore')
|
| 37 |
+
|
| 38 |
+
try:
|
| 39 |
+
import numpy
|
| 40 |
+
print(f'✅ NumPy {numpy.__version__}')
|
| 41 |
+
except Exception as e:
|
| 42 |
+
print(f'❌ NumPy: {e}')
|
| 43 |
+
|
| 44 |
+
try:
|
| 45 |
+
import cv2
|
| 46 |
+
print(f'✅ OpenCV {cv2.__version__}')
|
| 47 |
+
except Exception as e:
|
| 48 |
+
print(f'❌ OpenCV: {e}')
|
| 49 |
+
|
| 50 |
+
try:
|
| 51 |
+
import torch
|
| 52 |
+
print(f'✅ PyTorch {torch.__version__}')
|
| 53 |
+
except Exception as e:
|
| 54 |
+
print(f'❌ PyTorch: {e}')
|
| 55 |
+
|
| 56 |
+
try:
|
| 57 |
+
import transformers
|
| 58 |
+
print(f'✅ Transformers {transformers.__version__}')
|
| 59 |
+
except Exception as e:
|
| 60 |
+
print(f'❌ Transformers: {e}')
|
| 61 |
+
"
|
| 62 |
+
|
| 63 |
+
echo "🌐 Starting Flask application..."
|
| 64 |
+
exec python3 app.py
|