Spaces:
Running
Running
| import sys | |
| import subprocess | |
| def check_dependencies(): | |
| """Check if required packages are installed""" | |
| required_packages = [ | |
| 'fastapi', | |
| 'uvicorn', | |
| 'torch', | |
| 'transformers', | |
| 'clip', | |
| 'PIL' | |
| ] | |
| missing = [] | |
| for package in required_packages: | |
| try: | |
| if package == 'PIL': | |
| __import__('PIL') | |
| else: | |
| __import__(package) | |
| except ImportError: | |
| missing.append(package) | |
| return missing | |
| def main(): | |
| print("=" * 80) | |
| print("VQA BACKEND API - STARTUP CHECK") | |
| print("=" * 80) | |
| print("\nπ¦ Checking dependencies...") | |
| missing = check_dependencies() | |
| if missing: | |
| print(f"\nβ Missing packages: {', '.join(missing)}") | |
| print("\nπ‘ To install missing packages:") | |
| print(" pip install -r requirements_api.txt") | |
| print("\nOr if you already have VQA dependencies installed:") | |
| print(" pip install fastapi uvicorn python-multipart") | |
| sys.exit(1) | |
| print("β All dependencies found!") | |
| print("\nπ Checking model checkpoints...") | |
| import os | |
| base_checkpoint = "vqa_checkpoint.pt" | |
| spatial_checkpoint = "vqa_spatial_checkpoint.pt" | |
| if not os.path.exists(base_checkpoint): | |
| print(f"β Missing: {base_checkpoint}") | |
| print(" Please ensure the base model checkpoint is in the project root") | |
| sys.exit(1) | |
| if not os.path.exists(spatial_checkpoint): | |
| print(f"β Missing: {spatial_checkpoint}") | |
| print(" Please ensure the spatial model checkpoint is in the project root") | |
| sys.exit(1) | |
| print(f"β Found {base_checkpoint}") | |
| print(f"β Found {spatial_checkpoint}") | |
| print("\n" + "=" * 80) | |
| print("π STARTING BACKEND API SERVER") | |
| print("=" * 80) | |
| print("\nπ Configuration:") | |
| print(" - Host: 0.0.0.0 (accessible from network)") | |
| print(" - Port: 8000") | |
| print("\nπ Access URLs:") | |
| print(" - Local: http://localhost:8000") | |
| print(" - Network: http://<your-ip>:8000") | |
| print(" - Docs: http://localhost:8000/docs") | |
| print("\nπ‘ For mobile testing:") | |
| print(" 1. Find your local IP: ipconfig (Windows) or ifconfig (Mac/Linux)") | |
| print(" 2. Update API_URL in mobile app to http://<your-ip>:8000") | |
| print(" 3. Ensure phone and computer are on same network") | |
| print("=" * 80 + "\n") | |
| try: | |
| from backend_api import app | |
| import uvicorn | |
| uvicorn.run( | |
| app, | |
| host="0.0.0.0", | |
| port=8000, | |
| log_level="info" | |
| ) | |
| except Exception as e: | |
| print(f"\nβ Error starting server: {e}") | |
| print("\nPlease check:") | |
| print(" 1. All dependencies are installed") | |
| print(" 2. Model checkpoints are present") | |
| print(" 3. No other service is using port 8000") | |
| sys.exit(1) | |
| if __name__ == "__main__": | |
| main() |