from fastapi import FastAPI, HTTPException from pydantic import BaseModel import os from dotenv import load_dotenv import logging # Set up logging logging.basicConfig(level=logging.INFO) logger = logging.getLogger(__name__) # Load environment variables load_dotenv() # Initialize FastAPI app app = FastAPI(title="Mental Health Counselor API") # Initialize global storage DATA_DIR = os.path.join(os.path.dirname(__file__), "data") os.makedirs(DATA_DIR, exist_ok=True) os.makedirs(os.path.join(DATA_DIR, "users"), exist_ok=True) os.makedirs(os.path.join(DATA_DIR, "sessions"), exist_ok=True) os.makedirs(os.path.join(DATA_DIR, "conversations"), exist_ok=True) os.makedirs(os.path.join(DATA_DIR, "feedback"), exist_ok=True) # Simple health check route @app.get("/") async def root(): return { "status": "ok", "message": "Mental Health Counselor API is running", "api_version": "1.0.0", "backend_info": "FastAPI on Hugging Face Spaces" } # Health check endpoint @app.get("/health") async def health_check(): return {"status": "ok", "message": "Mental Health Counselor API is running"} # Metadata endpoint @app.get("/metadata") async def get_metadata(): return { "api_version": "1.0.0", "endpoints": [ "/", "/health", "/metadata" ], "provider": "Mental Health Counselor API on Hugging Face Spaces", "deployment_type": "Hugging Face Spaces Docker", "description": "This API provides functionality for a mental health counseling application.", "frontend": "Deployed separately on Vercel" } # Try to import the full API if available try: import api_mental_health # If the import succeeds, log success but handle routes differently logger.info("Successfully imported full API module") # Instead of using include_router, add the routes manually # Add a status endpoint for the full API @app.get("/full-api-status") async def full_api_status(): return { "status": "active", "message": "Full API module is active", "routes_available": True } # Use the api_mental_health module's app directly # Override the app variable to use the full API app app = api_mental_health.app # Re-add the basic endpoints to the full API app @app.get("/") async def root_override(): return { "status": "ok", "message": "Mental Health Counselor API is running (Full API)", "api_version": "1.0.0", "backend_info": "FastAPI on Hugging Face Spaces" } except ImportError as e: logger.warning(f"Could not import full API module: {e}") @app.get("/full-api-status") async def full_api_status(): return { "status": "unavailable", "message": "Full API module could not be imported", "error": str(e) }