File size: 2,967 Bytes
e62f11c
8242927
6ca0914
8242927
6ca0914
 
 
 
 
 
8242927
 
 
6ca0914
 
 
e62f11c
8242927
 
 
 
 
 
 
e62f11c
 
 
e151d55
e62f11c
 
 
 
e151d55
 
e62f11c
6ca0914
 
e62f11c
6ca0914
e62f11c
8242927
 
e62f11c
 
 
 
 
 
 
 
 
 
 
 
e151d55
e62f11c
 
 
9edf83b
e62f11c
e151d55
9edf83b
e62f11c
 
 
8242927
e62f11c
9edf83b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8242927
9edf83b
e62f11c
 
 
 
 
e151d55
e62f11c
 
 
e151d55
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
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)
        }