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() |