Files

105 lines
2.9 KiB
Bash
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#!/bin/bash
# BDFR Web Interface Startup Script
# Compatible with Linux, macOS, and other Unix-like systems
set -e # Exit on any error
# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m' # No Color
# Function to print colored output
print_info() {
echo -e "${BLUE}$1${NC}"
}
print_success() {
echo -e "${GREEN}$1${NC}"
}
print_warning() {
echo -e "${YELLOW}⚠️ $1${NC}"
}
print_error() {
echo -e "${RED}$1${NC}"
}
# Check if we're in the right directory
if [[ ! -f "requirements.txt" ]] || [[ ! -d "app" ]]; then
print_error "Error: Please run this script from the web_interface directory"
echo "Usage: ./start.sh"
exit 1
fi
print_info "BDFR Web Interface Startup"
echo "=================================================="
# Check Python version
print_info "Checking Python version..."
PYTHON_VERSION=$(python3 --version 2>&1 | awk '{print $2}')
print_success "Python version: $PYTHON_VERSION"
# Check if Python 3.8+ is available
PYTHON_MAJOR=$(echo $PYTHON_VERSION | cut -d. -f1)
PYTHON_MINOR=$(echo $PYTHON_VERSION | cut -d. -f2)
if [[ $PYTHON_MAJOR -lt 3 ]] || [[ $PYTHON_MAJOR -eq 3 && $PYTHON_MINOR -lt 8 ]]; then
print_error "Python 3.8 or higher is required"
print_error "Current version: $PYTHON_VERSION"
exit 1
fi
# Install dependencies
print_info "Checking and installing dependencies..."
if [[ -f "requirements.txt" ]]; then
# Check if pip is available
if ! command -v pip3 &> /dev/null; then
print_error "pip3 is not installed. Please install Python 3 and pip first."
exit 1
fi
# Install/update requirements
print_info "Installing Python dependencies..."
pip3 install -r requirements.txt
if [[ $? -eq 0 ]]; then
print_success "Dependencies installed successfully"
else
print_error "Failed to install dependencies"
exit 1
fi
else
print_error "requirements.txt not found"
exit 1
fi
# Check if BDFR module is available
print_info "Checking BDFR module availability..."
if python3 -c "import bdfr" 2>/dev/null; then
print_success "BDFR module found"
else
print_warning "BDFR module not found in Python path"
print_warning "Make sure the parent directory is in your Python path"
print_warning "Or run this script from the project root directory"
fi
# Start the server
echo ""
echo "=================================================="
print_info "Starting BDFR Web Interface..."
print_info "Server will be available at: http://localhost:8000"
print_info "API documentation at: http://localhost:8000/docs"
print_info "Press Ctrl+C to stop the server"
echo "=================================================="
# Start uvicorn server with proper error handling
python3 -m uvicorn app.main:app --host 0.0.0.0 --port 8000 --reload
# This code runs when the server is stopped
echo ""
print_info "BDFR Web Interface stopped"