Spaces:
Sleeping
Sleeping
Fix Dockerfile & Gradio compatibility
Browse files- Dockerfile +16 -17
- app.py +12 -8
- 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=/
|
7 |
-
ENV MPLCONFIGDIR=/
|
8 |
-
ENV HF_HOME=/
|
9 |
-
ENV TORCH_HOME=/
|
10 |
-
ENV TRANSFORMERS_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 /
|
22 |
-
/
|
23 |
-
/
|
24 |
-
/
|
25 |
-
|
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
|
47 |
RUN chown -R appuser:appuser /app
|
48 |
|
49 |
# Switch to non-root user
|
50 |
USER appuser
|
51 |
|
52 |
-
# Create a startup script
|
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": "/
|
19 |
-
"MPLCONFIGDIR": "/
|
20 |
-
"HF_HOME": "/
|
21 |
-
"TORCH_HOME": "/
|
22 |
-
"TRANSFORMERS_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 |
-
|
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
|