| | |
| | """ |
| | 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...") |
| | |
| | |
| | if sys.version_info < (3, 8): |
| | print("β Python 3.8+ is required") |
| | return False |
| | |
| | print(f"β
Python {sys.version.split()[0]}") |
| | |
| | |
| | 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) |
| | |
| | |
| | if not check_system(): |
| | sys.exit(1) |
| | |
| | |
| | if not install_requirements(): |
| | sys.exit(1) |
| | |
| | |
| | create_models_directory() |
| | |
| | |
| | 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() |