DPSGDTool / start_server.sh
Shuya Feng
feat: Implement DP-SGD Explorer web application with Flask backend, interactive frontend, and easy deployment script
6640531
raw
history blame
1.69 kB
#!/bin/bash
# Colors for output
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
RED='\033[0;31m'
NC='\033[0m' # No Color
# Function to print colored messages
print_message() {
echo -e "${2}${1}${NC}"
}
# Check if Python 3 is installed
if ! command -v python3 &> /dev/null; then
print_message "Python 3 is not installed. Please install Python 3 first." "$RED"
exit 1
fi
# Check Python version
PYTHON_VERSION=$(python3 -c 'import sys; print(".".join(map(str, sys.version_info[:2])))')
print_message "Found Python version: $PYTHON_VERSION" "$GREEN"
# Create virtual environment if it doesn't exist
if [ ! -d ".venv" ]; then
print_message "Creating virtual environment..." "$YELLOW"
python3 -m venv .venv
if [ $? -ne 0 ]; then
print_message "Failed to create virtual environment. Please install python3-venv package." "$RED"
exit 1
fi
fi
# Activate virtual environment
print_message "Activating virtual environment..." "$GREEN"
source .venv/bin/activate
if [ $? -ne 0 ]; then
print_message "Failed to activate virtual environment." "$RED"
exit 1
fi
# Install or upgrade pip
print_message "Upgrading pip..." "$YELLOW"
python3 -m pip install --upgrade pip
# Install requirements
print_message "Installing dependencies..." "$YELLOW"
pip install -r requirements.txt
if [ $? -ne 0 ]; then
print_message "Failed to install dependencies." "$RED"
exit 1
fi
# Start the Flask application
print_message "\n=== DP-SGD Explorer Backend ===" "$GREEN"
print_message "Starting server..." "$GREEN"
print_message "The application will be available at http://127.0.0.1:5000\n" "$YELLOW"
# Set Python path and start server
PYTHONPATH=. python3 run.py