File size: 1,357 Bytes
5dc4520
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
#!/usr/bin/env python3
"""
Startup script for Hugging Face Spaces deployment.
This script handles the specific requirements for HF Spaces environment.
"""

import os
import sys
import logging
from pathlib import Path

# Add the ai_med_extract module to Python path
current_dir = Path(__file__).parent
ai_med_extract_path = current_dir / "services" / "ai-service" / "src"
sys.path.insert(0, str(ai_med_extract_path))

# Set environment variables for HF Spaces
os.environ.setdefault('HF_SPACES', 'true')
os.environ.setdefault('PYTHONUNBUFFERED', '1')

# Configure logging
logging.basicConfig(
    level=logging.INFO,
    format="%(asctime)s - %(levelname)s - %(message)s"
)

def main():
    """Main entry point for HF Spaces deployment."""
    try:
        # Import and create the FastAPI app
        from ai_med_extract.app import create_app
        
        logging.info("Creating FastAPI application for HF Spaces...")
        app = create_app()
        
        # Start the application with uvicorn
        import uvicorn
        logging.info("Starting uvicorn server...")
        uvicorn.run(
            app,
            host="0.0.0.0",
            port=7860,
            log_level="info"
        )
        
    except Exception as e:
        logging.error(f"Failed to start application: {e}")
        sys.exit(1)

if __name__ == "__main__":
    main()