Spaces:
Sleeping
Sleeping
File size: 2,425 Bytes
8242927 6ca0914 8242927 6ca0914 8242927 6ca0914 8242927 6ca0914 8242927 6ca0914 8242927 6ca0914 8242927 6ca0914 8242927 6ca0914 8242927 6ca0914 8242927 6ca0914 8242927 |
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 |
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, try to add those routes
logger.info("Successfully imported full API module")
# Add a placeholder for full functionality
@app.get("/full-api-status")
async def full_api_status():
return {
"status": "imported",
"message": "Full API module was imported successfully, but endpoints may require additional setup"
}
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)
}
|