psypredict-backend / README.md
therandomuser03's picture
update backend for AWS
286428e
metadata
title: PsyPredict [Backend]
emoji: 🧠
colorFrom: indigo
colorTo: purple
sdk: docker
pinned: false

PsyPredict - Backend

FastAPI backend for PsyPredict β€” production-grade multimodal clinical AI system.

What Runs Here

Service Technology
API Framework FastAPI + Uvicorn
LLM Inference Ollama / Llama3 (local)
Text Emotion DistilBERT (bhadresh-savani/distilbert-base-uncased-emotion)
Crisis Detection Zero-shot NLI (MiniLM)
Face Emotion Keras CNN (custom trained, emotion_model_trained.h5)
Remedies CSV lookup (MEDICATION.csv)

Endpoints

Method Path Description
POST /api/chat Main therapist β€” returns PsychReport
POST /api/predict/emotion Facial emotion detection
GET /api/get_advice Remedy/condition lookup
POST /api/analyze/text Text emotion + crisis score
GET /api/health System health check

Running Locally

# 1. Install Ollama + LLaMA 3 (one-time)
winget install Ollama.Ollama
ollama pull llama3

# 2. Install dependencies
pip install -r requirements.txt

# 3. Start server
uvicorn app.main:app --host 0.0.0.0 --port 7860 --reload

Swagger docs: http://localhost:7860/docs

Key Files

app/
β”œβ”€β”€ main.py                   # FastAPI app factory
β”œβ”€β”€ config.py                 # Pydantic Settings
β”œβ”€β”€ schemas.py                # All request/response models (PsychReport etc.)
β”œβ”€β”€ services/
β”‚   β”œβ”€β”€ ollama_engine.py      # LLaMA 3 async client
β”‚   β”œβ”€β”€ text_emotion_engine.py# DistilBERT classifier
β”‚   β”œβ”€β”€ crisis_engine.py      # Zero-shot NLI crisis detection
β”‚   β”œβ”€β”€ fusion_engine.py      # Multimodal weighted fusion
β”‚   β”œβ”€β”€ emotion_engine.py     # Keras CNN face emotion (preserved)
β”‚   └── remedy_engine.py      # CSV remedy lookup (preserved)
└── api/endpoints/
    β”œβ”€β”€ therapist.py          # POST /api/chat
    β”œβ”€β”€ facial.py             # POST /api/predict/emotion
    β”œβ”€β”€ remedies.py           # GET  /api/get_advice
    └── analysis.py           # POST /api/analyze/text + GET /api/health