Spaces:
Sleeping
Sleeping
Cam commited on
Commit ·
4d69b87
1
Parent(s): 4c8d706
change approach to docker file
Browse files- Dockerfile +18 -10
- setup.sh +16 -18
Dockerfile
CHANGED
|
@@ -6,24 +6,29 @@ WORKDIR /app
|
|
| 6 |
# Copy your code
|
| 7 |
COPY . /app
|
| 8 |
|
| 9 |
-
#
|
| 10 |
-
RUN pip install --no-cache-dir
|
| 11 |
|
| 12 |
-
#
|
| 13 |
-
RUN mkdir -p /
|
| 14 |
-
|
| 15 |
-
chmod -R 777 /usr/local/lib/python3.10/site-packages
|
| 16 |
|
| 17 |
-
# Create
|
|
|
|
|
|
|
|
|
|
|
|
|
| 18 |
RUN mkdir -p /app/guardrails_fallback
|
| 19 |
RUN echo 'class DetectJailbreak:\n def __init__(self, *args, **kwargs):\n print("Using fallback DetectJailbreak implementation")\n pass\n\nclass ToxicLanguage:\n def __init__(self, *args, **kwargs):\n print("Using fallback ToxicLanguage implementation")\n pass' > /app/guardrails_fallback/__init__.py
|
| 20 |
|
|
|
|
|
|
|
|
|
|
| 21 |
# Create a non-root user
|
| 22 |
RUN useradd -m -u 1000 appuser
|
| 23 |
|
| 24 |
-
#
|
| 25 |
-
RUN
|
| 26 |
-
RUN sed -i 's/pip install/pip install --user/g' /app/setup.sh
|
| 27 |
|
| 28 |
# Change ownership
|
| 29 |
RUN chown -R appuser:appuser /app /home/appuser
|
|
@@ -36,5 +41,8 @@ ENV PATH="/home/appuser/.local/bin:${PATH}"
|
|
| 36 |
# Switch to non-root user
|
| 37 |
USER appuser
|
| 38 |
|
|
|
|
|
|
|
|
|
|
| 39 |
# Launch the app
|
| 40 |
CMD ["streamlit", "run", "/app/app.py", "--server.port", "7860", "--server.address", "0.0.0.0"]
|
|
|
|
| 6 |
# Copy your code
|
| 7 |
COPY . /app
|
| 8 |
|
| 9 |
+
# First install critical packages system-wide
|
| 10 |
+
RUN pip install --no-cache-dir streamlit guardrails-ai
|
| 11 |
|
| 12 |
+
# Set proper permissions for system directories where packages get installed
|
| 13 |
+
RUN mkdir -p /usr/local/bin && chmod -R 777 /usr/local/bin
|
| 14 |
+
RUN chmod -R 777 /usr/local/lib/python3.10/site-packages
|
|
|
|
| 15 |
|
| 16 |
+
# Create necessary directories with appropriate permissions
|
| 17 |
+
RUN mkdir -p /app/.phoenix /tmp/.phoenix /app/.guardrails && \
|
| 18 |
+
chmod -R 777 /app/.phoenix /tmp/.phoenix /app/.guardrails
|
| 19 |
+
|
| 20 |
+
# Create fallback implementations
|
| 21 |
RUN mkdir -p /app/guardrails_fallback
|
| 22 |
RUN echo 'class DetectJailbreak:\n def __init__(self, *args, **kwargs):\n print("Using fallback DetectJailbreak implementation")\n pass\n\nclass ToxicLanguage:\n def __init__(self, *args, **kwargs):\n print("Using fallback ToxicLanguage implementation")\n pass' > /app/guardrails_fallback/__init__.py
|
| 23 |
|
| 24 |
+
# Make the setup script executable
|
| 25 |
+
RUN chmod +x /app/setup.sh
|
| 26 |
+
|
| 27 |
# Create a non-root user
|
| 28 |
RUN useradd -m -u 1000 appuser
|
| 29 |
|
| 30 |
+
# Install remaining dependencies (can use system or user install)
|
| 31 |
+
RUN pip install --no-cache-dir -r requirements.txt
|
|
|
|
| 32 |
|
| 33 |
# Change ownership
|
| 34 |
RUN chown -R appuser:appuser /app /home/appuser
|
|
|
|
| 41 |
# Switch to non-root user
|
| 42 |
USER appuser
|
| 43 |
|
| 44 |
+
# Expose the port for Streamlit
|
| 45 |
+
EXPOSE 7860
|
| 46 |
+
|
| 47 |
# Launch the app
|
| 48 |
CMD ["streamlit", "run", "/app/app.py", "--server.port", "7860", "--server.address", "0.0.0.0"]
|
setup.sh
CHANGED
|
@@ -1,23 +1,21 @@
|
|
| 1 |
#!/bin/bash
|
| 2 |
-
# setup.sh - Run once when the Streamlit app starts
|
| 3 |
|
| 4 |
-
echo "
|
| 5 |
|
| 6 |
-
#
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
fi
|
| 22 |
|
| 23 |
echo "Setup completed!"
|
|
|
|
| 1 |
#!/bin/bash
|
|
|
|
| 2 |
|
| 3 |
+
echo "Setting up environment..."
|
| 4 |
|
| 5 |
+
# Configure guardrails with token
|
| 6 |
+
python -c "
|
| 7 |
+
import os
|
| 8 |
+
import guardrails as gd
|
| 9 |
+
try:
|
| 10 |
+
gd.configure(api_endpoint='https://api.guardrailsai.com', api_key=os.environ.get('GUARDRAILS_API_KEY', ''))
|
| 11 |
+
print('Guardrails configured successfully')
|
| 12 |
+
except Exception as e:
|
| 13 |
+
print(f'Warning: Could not configure guardrails: {e}')
|
| 14 |
+
"
|
| 15 |
+
|
| 16 |
+
# Try installing validators but don't fail if they don't work
|
| 17 |
+
echo "Installing Guardrails validators..."
|
| 18 |
+
guardrails hub install hub://guardrails/detect_jailbreak || echo "Warning: Could not install detect_jailbreak validator"
|
| 19 |
+
guardrails hub install hub://guardrails/toxic_language || echo "Warning: Could not install toxic_language validator"
|
|
|
|
| 20 |
|
| 21 |
echo "Setup completed!"
|