#!/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()