LamiaYT commited on
Commit
bbe4b6b
·
1 Parent(s): f1c2e53

Fix Dockerfile & Gradio compatibility

Browse files
Files changed (3) hide show
  1. Dockerfile +16 -17
  2. app.py +12 -8
  3. txt.txt +0 -0
Dockerfile CHANGED
@@ -1,29 +1,28 @@
1
  # Use a base Python image with better compatibility
2
  FROM python:3.10-slim
3
 
4
- # Set environment variables to fix permission issues
5
  ENV PYTHONUNBUFFERED=1
6
- ENV NLTK_DATA=/app/nltk_data
7
- ENV MPLCONFIGDIR=/app/matplotlib_cache
8
- ENV HF_HOME=/app/huggingface_cache
9
- ENV TORCH_HOME=/app/torch_cache
10
- ENV TRANSFORMERS_CACHE=/app/huggingface_cache
11
  ENV GRADIO_SERVER_NAME=0.0.0.0
12
  ENV GRADIO_SERVER_PORT=7860
13
 
14
  # Create app user and group for better security
15
- RUN groupadd -r appuser && useradd -r -g appuser appuser
16
 
17
  # Set working directory
18
  WORKDIR /app
19
 
20
  # Create cache directories with proper permissions
21
- RUN mkdir -p /app/nltk_data \
22
- /app/matplotlib_cache \
23
- /app/huggingface_cache \
24
- /app/torch_cache \
25
- /app/temp && \
26
- chown -R appuser:appuser /app
27
 
28
  # Install system dependencies
29
  RUN apt-get update && apt-get install -y \
@@ -43,13 +42,13 @@ RUN pip install --upgrade pip && \
43
  # Copy application code
44
  COPY . .
45
 
46
- # Change ownership of all app files to appuser
47
  RUN chown -R appuser:appuser /app
48
 
49
  # Switch to non-root user
50
  USER appuser
51
 
52
- # Create a startup script to handle initialization
53
  RUN echo '#!/bin/bash\n\
54
  echo "Starting GAIA Agent..."\n\
55
  echo "Environment check:"\n\
@@ -63,9 +62,9 @@ python app.py' > /app/start.sh && chmod +x /app/start.sh
63
  # Expose the port
64
  EXPOSE 7860
65
 
66
- # Health check
67
  HEALTHCHECK --interval=30s --timeout=10s --start-period=60s --retries=3 \
68
  CMD curl -f http://localhost:7860/ || exit 1
69
 
70
  # Run the application
71
- CMD ["/app/start.sh"]
 
1
  # Use a base Python image with better compatibility
2
  FROM python:3.10-slim
3
 
4
+ # Set environment variables to fix permission issues (use /tmp paths)
5
  ENV PYTHONUNBUFFERED=1
6
+ ENV NLTK_DATA=/tmp/nltk_data
7
+ ENV MPLCONFIGDIR=/tmp/matplotlib_cache
8
+ ENV HF_HOME=/tmp/huggingface_cache
9
+ ENV TORCH_HOME=/tmp/torch_cache
10
+ ENV TRANSFORMERS_CACHE=/tmp/huggingface_cache
11
  ENV GRADIO_SERVER_NAME=0.0.0.0
12
  ENV GRADIO_SERVER_PORT=7860
13
 
14
  # Create app user and group for better security
15
+ RUN groupadd -r appuser && useradd -r -g appuser -u 1000 -m -s /bin/bash appuser
16
 
17
  # Set working directory
18
  WORKDIR /app
19
 
20
  # Create cache directories with proper permissions
21
+ RUN mkdir -p /tmp/nltk_data \
22
+ /tmp/matplotlib_cache \
23
+ /tmp/huggingface_cache \
24
+ /tmp/torch_cache \
25
+ && chown -R appuser:appuser /tmp
 
26
 
27
  # Install system dependencies
28
  RUN apt-get update && apt-get install -y \
 
42
  # Copy application code
43
  COPY . .
44
 
45
+ # Change ownership of app files
46
  RUN chown -R appuser:appuser /app
47
 
48
  # Switch to non-root user
49
  USER appuser
50
 
51
+ # Create a startup script
52
  RUN echo '#!/bin/bash\n\
53
  echo "Starting GAIA Agent..."\n\
54
  echo "Environment check:"\n\
 
62
  # Expose the port
63
  EXPOSE 7860
64
 
65
+ # Health check (optional but helpful)
66
  HEALTHCHECK --interval=30s --timeout=10s --start-period=60s --retries=3 \
67
  CMD curl -f http://localhost:7860/ || exit 1
68
 
69
  # Run the application
70
+ CMD ["/app/start.sh"]
app.py CHANGED
@@ -13,14 +13,18 @@ import gradio as gr
13
 
14
  # --- Environment variable setup to fix permission issues ---
15
  def setup_environment():
16
- """Setup environment variables and create necessary directories"""
17
  env_vars = {
18
- "NLTK_DATA": "/app/nltk_data",
19
- "MPLCONFIGDIR": "/app/matplotlib_cache",
20
- "HF_HOME": "/app/huggingface_cache",
21
- "TORCH_HOME": "/app/torch_cache",
22
- "TRANSFORMERS_CACHE": "/app/huggingface_cache"
23
  }
 
 
 
 
 
24
 
25
  for var, path in env_vars.items():
26
  os.environ[var] = path
@@ -363,6 +367,6 @@ if __name__ == "__main__":
363
  demo.launch(
364
  server_name="0.0.0.0",
365
  server_port=7860,
366
- show_error=True,
367
- show_tips=True
368
  )
 
13
 
14
  # --- Environment variable setup to fix permission issues ---
15
  def setup_environment():
 
16
  env_vars = {
17
+ "NLTK_DATA": "/tmp/nltk_data",
18
+ "MPLCONFIGDIR": "/tmp/matplotlib_cache",
19
+ "HF_HOME": "/tmp/huggingface_cache",
20
+ "TORCH_HOME": "/tmp/torch_cache",
21
+ "TRANSFORMERS_CACHE": "/tmp/huggingface_cache"
22
  }
23
+
24
+ for var, path in env_vars.items():
25
+ os.environ[var] = path
26
+ os.makedirs(path, exist_ok=True)
27
+
28
 
29
  for var, path in env_vars.items():
30
  os.environ[var] = path
 
367
  demo.launch(
368
  server_name="0.0.0.0",
369
  server_port=7860,
370
+ show_error=True
371
+
372
  )
txt.txt ADDED
File without changes