CoolFace
Apppublic

VidurAGI/user_wellbeing_Dossier

sourceHugging Facemitupdated 16d agoView on Hugging Face
0likes
App README

Sattvastha Data Generation API

FastAPI service that generates a structured wellbeing dossier (data.json-style payload) for a Sattvastha user. Pulls assessments, mood check-ins, journal entries, and chat history from MongoDB, then uses Groq to produce schema-conforming weekly wellbeing frames. The result is upserted into the userdossiers collection (one document per user, frames merged by calendar week).

Endpoints

MethodPathPurpose
POST/generateGenerate dossier for {email, weeks} and upsert
GET/healthLiveness probe
GET/docsInteractive Swagger UI

Example request

bash
curl -X POST https://<your-space>.hf.space/generate \
  -H "Content-Type: application/json" \
  -d '{
    "email": "user@example.com",
    "weeks": 8,
    "conversations": 6,
    "persist": true,
    "include_payload": true
  }'

Example response

json
{
  "email": "user@example.com",
  "generated_at": "2026-05-19T03:14:15.000000+00:00",
  "duration_seconds": 42.18,
  "weeks_generated": 8,
  "chat_turns": 12,
  "schema_valid": true,
  "schema_errors": [],
  "mongo_persisted": true,
  "total_frames_in_mongo": 8,
  "new_or_updated_frames": 8,
  "payload": { "personal_memory": { ... }, "recent_chat_memory": [ ... ], "wellbeing_frames": [ ... ] }
}

Environment variables

Set these as Secrets in your Hugging Face Space settings (Settings → Variables and secrets → New secret):

NameRequiredDescription
GROQ_API_KEYyesGroq API key
MONGO_CONNECTION_STRINGyesMongoDB Atlas connection URI
MONGO_DB_NAMEnoDefaults to sattvastha

Persistence semantics

Each call to POST /generate upserts a single document into userdossiers keyed by user_id (the email).

  • —personal_memory — replaced every run.
  • —recent_chat_memory — replaced every run.
  • —wellbeing_frames — merged by week_start_date. If a calendar week already exists in the document, the new frame replaces it (latest analysis wins). Weeks not in the new batch are preserved. Running the pipeline weekly grows the dossier by ~1 frame per run.

To wipe a user's dossier and start over:

python
db["userdossiers"].delete_one({"user_id": "user@example.com"})

Local development

bash
pip install -r requirements.txt
export GROQ_API_KEY=...
export MONGO_CONNECTION_STRING=...
uvicorn data_generation_api:app --host 0.0.0.0 --port 7860 --reload

Then open http://localhost:7860/docs for the Swagger UI.

Notes

  • —A single /generate call takes ~30–60 s due to multiple Groq calls (sentiment + wellbeing frames).
  • —The pipeline anchors weekly buckets on the user's most recent activity, not on today — so a user who hasn't logged in for 2 weeks still gets relevant frames.
  • —Groq's openai/gpt-oss-120b has tight TPM limits on the ondemand tier. If you hit rate-limit errors on the frame-generation call, switch to `llama-3.3-70b-versatile` by editing `GROQFRAMEMODEL` in `datageneration_pipeline.py`.