File size: 1,582 Bytes
77da9e2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
"""
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()