thera-guide-ai / app.py
Said Lfagrouche
Prepare for Hugging Face Spaces deployment with simplified configuration
8242927
raw
history blame
2.43 kB
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)
}