Spaces:
Sleeping
Sleeping
File size: 2,928 Bytes
bb8f662 | 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 | 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() |