| |
| """ |
| Medical AI Assistant - FastAPI Only Entry Point |
| Simplified for backend integration |
| """ |
|
|
| import os |
| import sys |
| import logging |
| from pathlib import Path |
|
|
| |
| sys.path.insert(0, str(Path(__file__).parent)) |
|
|
| |
| logging.basicConfig( |
| level=logging.INFO, |
| format='%(asctime)s - %(name)s - %(levelname)s - %(message)s' |
| ) |
| logger = logging.getLogger(__name__) |
|
|
| def setup_environment(): |
| """Setup environment variables for FastAPI deployment""" |
| |
| os.environ.setdefault("TOKENIZERS_PARALLELISM", "false") |
| os.environ.setdefault("HF_HOME", "/tmp/huggingface") |
| os.environ.setdefault("TRANSFORMERS_CACHE", "/tmp/transformers") |
| |
| |
| os.environ.setdefault("HOST", "0.0.0.0") |
| os.environ.setdefault("PORT", "8000") |
| |
| logger.info("β
Environment configured for FastAPI Medical AI") |
|
|
| def main(): |
| """Main application entry point""" |
| try: |
| logger.info("π©Ί Starting Medical AI Assistant - FastAPI Edition") |
| |
| |
| setup_environment() |
| |
| |
| from fastapi_app import app |
| import uvicorn |
| |
| |
| port = int(os.getenv("PORT", 8000)) |
| host = os.getenv("HOST", "0.0.0.0") |
| |
| logger.info(f"π Starting FastAPI server on {host}:{port}") |
| logger.info(f"π API Documentation will be available at: http://{host}:{port}/docs") |
| logger.info(f"π Alternative docs at: http://{host}:{port}/redoc") |
| |
| |
| uvicorn.run( |
| app, |
| host=host, |
| port=port, |
| log_level="info", |
| reload=False, |
| access_log=True |
| ) |
| |
| except KeyboardInterrupt: |
| logger.info("π Application stopped by user") |
| except Exception as e: |
| logger.error(f"β Critical error in main application: {str(e)}", exc_info=True) |
| sys.exit(1) |
|
|
| |
| try: |
| from fastapi_app import app |
| logger.info("β
FastAPI app imported successfully") |
| except ImportError as e: |
| logger.error(f"β Failed to import FastAPI app: {str(e)}") |
| |
| from fastapi import FastAPI |
| app = FastAPI(title="Medical AI - Error", description="Failed to load main application") |
| |
| @app.get("/") |
| async def error_root(): |
| return {"error": "Medical AI Assistant failed to load properly"} |
|
|
| if __name__ == "__main__": |
| main() |