MedAI / deploy.sh
riteshkokam's picture
Create deploy.sh
8cc9aef verified
#!/bin/bash
# AI Doctor Deployment Script for Hugging Face Spaces
# This script helps set up and deploy the AI Doctor application
echo "πŸ₯ AI Doctor - Deployment Setup Script"
echo "======================================"
# Check if we're in the right directory
if [ ! -f "app.py" ]; then
echo "❌ Error: app.py not found. Please run this script from the project root directory."
exit 1
fi
# Function to check if command exists
command_exists() {
command -v "$1" >/dev/null 2>&1
}
# Check prerequisites
echo "πŸ” Checking prerequisites..."
if ! command_exists python3; then
echo "❌ Python 3 is required but not installed."
exit 1
fi
if ! command_exists pip; then
echo "❌ pip is required but not installed."
exit 1
fi
echo "βœ… Prerequisites check passed"
# Create virtual environment (optional for local development)
if [ "$1" = "--local" ]; then
echo "🐍 Setting up local development environment..."
if [ ! -d "venv" ]; then
python3 -m venv venv
echo "βœ… Virtual environment created"
fi
# Activate virtual environment
source venv/bin/activate
echo "βœ… Virtual environment activated"
# Install dependencies
echo "πŸ“¦ Installing dependencies..."
pip install -r requirements.txt
echo "βœ… Dependencies installed"
# Run the application
echo "πŸš€ Starting AI Doctor locally..."
python app.py
elif [ "$1" = "--test" ]; then
echo "πŸ§ͺ Running tests and validation..."
# Check if all required files exist
required_files=("app.py" "requirements.txt" "README.md")
for file in "${required_files[@]}"; do
if [ ! -f "$file" ]; then
echo "❌ Missing required file: $file"
exit 1
fi
done
echo "βœ… All required files present"
# Validate Python syntax
echo "πŸ” Validating Python syntax..."
python3 -m py_compile app.py
if [ $? -eq 0 ]; then
echo "βœ… Python syntax is valid"
else
echo "❌ Python syntax errors found"
exit 1
fi
# Check requirements format
echo "πŸ” Validating requirements.txt..."
pip install --dry-run -r requirements.txt > /dev/null 2>&1
if [ $? -eq 0 ]; then
echo "βœ… Requirements.txt is valid"
else
echo "❌ Issues found in requirements.txt"
exit 1
fi
echo "βœ… All tests passed! Ready for deployment."
elif [ "$1" = "--deploy" ]; then
echo "πŸš€ Preparing for Hugging Face Spaces deployment..."
# Create deployment checklist
echo "πŸ“‹ Deployment Checklist:"
echo " 1. βœ… Create Hugging Face account at https://huggingface.co"
echo " 2. βœ… Go to https://huggingface.co/spaces"
echo " 3. βœ… Click 'Create new Space'"
echo " 4. βœ… Choose 'Gradio' as SDK"
echo " 5. βœ… Upload these files:"
echo " - app.py (main application)"
echo " - requirements.txt (dependencies)"
echo " - README.md (documentation)"
echo " - .space (configuration - optional)"
echo " 6. βœ… Set hardware to 'CPU Basic' or 'T4 Small GPU'"
echo " 7. βœ… Make space public or private as needed"
echo " 8. βœ… Click 'Create Space'"
echo ""
echo "πŸŽ‰ Your AI Doctor will be live at: https://huggingface.co/spaces/YOUR_USERNAME/ai-doctor"
else
echo "Usage: $0 [--local|--test|--deploy]"
echo ""
echo "Options:"
echo " --local Set up and run locally for development"
echo " --test Run validation tests"
echo " --deploy Show deployment instructions"
echo ""
echo "For Hugging Face Spaces deployment, run: $0 --deploy"
fi
echo ""
echo "πŸ₯ AI Doctor Setup Complete!"
echo "For questions or issues, check the README.md file."