bhd82 commited on
Commit
47c1b66
·
verified ·
1 Parent(s): 69cf62c

Create Dockerfile

Browse files
Files changed (1) hide show
  1. Dockerfile +49 -0
Dockerfile ADDED
@@ -0,0 +1,49 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Use a lightweight Python base image
2
+ FROM python:3.9-slim
3
+
4
+ # Set working directory
5
+ WORKDIR /app
6
+
7
+ # Set environment variables
8
+ ENV HF_HOME="/tmp/huggingface/cache"
9
+ ENV FLASK_APP=app.py
10
+ ENV FLASK_ENV=production
11
+ ENV PYTHONUNBUFFERED=1
12
+ ENV CUDA_VISIBLE_DEVICES="-1" # Force CPU mode for compatibility
13
+
14
+ # Create Hugging Face cache directory with proper permissions
15
+ RUN mkdir -p /tmp/huggingface/cache && \
16
+ chmod -R 777 /tmp/huggingface/cache && \
17
+ apt-get update && \
18
+ apt-get install -y --no-install-recommends gcc python3-dev && \
19
+ rm -rf /var/lib/apt/lists/*
20
+
21
+ # Copy requirements and install dependencies
22
+ COPY requirements.txt .
23
+ RUN pip install --no-cache-dir -r requirements.txt
24
+
25
+ # Copy application code
26
+ COPY . .
27
+
28
+ # Create models directory if it doesn't exist
29
+ RUN mkdir -p models
30
+
31
+ # Ensure permissions for application files
32
+ RUN chmod -R 755 /app
33
+
34
+ # Expose application port (Hugging Face Spaces uses port 7860)
35
+ EXPOSE 7860
36
+
37
+ # Create a script to run the application
38
+ RUN echo '#!/bin/bash\n\
39
+ # Check if model files exist\n\
40
+ if [ ! -f "models/mobilenetv2_ham10000_finetuned_74.h5" ] || [ ! -f "models/efficientnetb0_skin_cancer_model_final_69.keras" ]; then\n\
41
+ echo "Warning: Model files not found. Please ensure models are uploaded to the models directory."\n\
42
+ fi\n\
43
+ \n\
44
+ # Run the Flask application\n\
45
+ flask run --host=0.0.0.0 --port=7860\n\
46
+ ' > /app/start.sh && chmod +x /app/start.sh
47
+
48
+ # Run the Flask application
49
+ CMD ["/app/start.sh"]