Spaces:
Sleeping
Sleeping
| """ | |
| API Server Entry Point | |
| Starts the FastAPI server for UI element detection. | |
| Usage: | |
| python app_api.py | |
| The API will be available at: | |
| - Root: http://localhost:8000 | |
| - Detect endpoint: http://localhost:8000/detect | |
| - Health check: http://localhost:8000/health | |
| - Interactive docs: http://localhost:8000/docs | |
| """ | |
| import os | |
| os.environ['PYTORCH_ENABLE_MPS_FALLBACK'] = '1' | |
| import uvicorn | |
| from api.endpoints import app | |
| def main(): | |
| """Start the API server""" | |
| # Get configuration from environment | |
| host = os.getenv("UVICORN_HOST", "0.0.0.0") | |
| port = int(os.getenv("UVICORN_PORT", "8000")) | |
| print("=" * 70) | |
| print("π CU-1 UI Element Detector - API Server") | |
| print("=" * 70) | |
| print("\nπ Architecture:") | |
| print(" RF-DETR: Detects UI elements (single class)") | |
| print(" CLIP: Classifies elements into 6 types") | |
| print(" OCR: Extracts text content") | |
| print(" BLIP: Generates visual descriptions") | |
| print(f"\nπ‘ API Endpoints:") | |
| print(f" - Root: http://localhost:{port}") | |
| print(f" - Detect: http://localhost:{port}/detect") | |
| print(f" - Health: http://localhost:{port}/health") | |
| print(f" - Docs: http://localhost:{port}/docs") | |
| print("\nπ‘ Tip: The Gradio UI connects to this API") | |
| print(" Run 'python app_ui.py' in another terminal") | |
| print(" Or run 'python app.py' to start both automatically") | |
| print("=" * 70 + "\n") | |
| uvicorn.run( | |
| app, | |
| host=host, | |
| port=port, | |
| log_level="info" | |
| ) | |
| if __name__ == "__main__": | |
| main() | |