File size: 2,637 Bytes
088ebc0
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
#!/usr/bin/env python3
"""
Setup script for Aircraft Classifier Gradio deployment
"""
import os
import sys
import subprocess
import urllib.request
from pathlib import Path

def install_requirements():
    """Install required packages"""
    print("πŸ“¦ Installing requirements...")
    try:
        subprocess.check_call([sys.executable, "-m", "pip", "install", "-r", "requirements.txt"])
        print("βœ… Requirements installed successfully")
    except subprocess.CalledProcessError as e:
        print(f"❌ Error installing requirements: {e}")
        return False
    return True

def create_models_directory():
    """Create models directory if it doesn't exist"""
    models_dir = Path("models")
    models_dir.mkdir(exist_ok=True)
    print(f"πŸ“ Models directory created: {models_dir}")

def download_sample_model():
    """Download or create a placeholder model file"""
    model_path = Path("models/aircraft_classifier.pth")
    
    if not model_path.exists():
        print("⚠️ No trained model found.")
        print("πŸ’‘ To use the classifier, you need to:")
        print("   1. Run the training notebook: aircraft_classifier.ipynb")
        print("   2. Save the trained model to: models/aircraft_classifier.pth")
        print("   3. Or the app will use random weights (for demo purposes)")

def check_system():
    """Check system requirements"""
    print("πŸ” Checking system requirements...")
    
    # Check Python version
    if sys.version_info < (3, 8):
        print("❌ Python 3.8+ is required")
        return False
    
    print(f"βœ… Python {sys.version.split()[0]}")
    
    # Check if CUDA is available
    try:
        import torch
        if torch.cuda.is_available():
            print(f"βœ… CUDA available: {torch.cuda.get_device_name(0)}")
        else:
            print("⚠️ CUDA not available, using CPU")
    except ImportError:
        print("⚠️ PyTorch not installed yet")
    
    return True

def main():
    """Main setup function"""
    print("πŸ›©οΈ Aircraft Classifier - Setup Script")
    print("=" * 50)
    
    # Check system requirements
    if not check_system():
        sys.exit(1)
    
    # Install requirements
    if not install_requirements():
        sys.exit(1)
    
    # Create necessary directories
    create_models_directory()
    
    # Check for model file
    download_sample_model()
    
    print("\nπŸŽ‰ Setup complete!")
    print("\nπŸš€ To start the Gradio interface:")
    print("   python app.py")
    print("\nπŸ“š To train the model:")
    print("   jupyter notebook aircraft_classifier.ipynb")

if __name__ == "__main__":
    main()