Inspiration
Maternal mortality remains a critical challenge in low-resource settings. In Migori County, Kenya, pregnant women often lack access to timely, culturally appropriate antenatal education. Many cannot attend regular clinic visits due to distance, cost, or time constraints, yet they carry mobile phones with WhatsApp installed.
We were inspired to leverage Google's Gemini API to create an AI-powered WhatsApp chatbot that brings expert antenatal guidance directly to expectant mothers' phones—available 24/7, in both English and Swahili.
What it does
Zeya is an AI-powered maternal health assistant accessible via WhatsApp. It provides:
- Personalized antenatal education based on gestational age
- Danger sign detection with automatic emergency alerts
- Database-driven facility referrals for local hospitals in Migori County
- Bilingual support (English & Swahili)
- 3-step registration (consent → name → gestational age)
- Contextual AI responses using Gemini 3 Flash Preview with WHO/Kenya MOH guidelines
When a user sends a message, the system:
- Detects 8 categories of obstetric danger signs using regex patterns
- If detected, immediately provides emergency contacts for nearby verified health facilities
- Otherwise, generates contextualized educational content via Gemini API with conversation history
How we built it
Backend (Python/FastAPI)
- Gemini 3 Flash Preview (
gemini-3-flash-preview) for AI response generation - WhatsApp Cloud API for messaging
- PostgreSQL with async SQLAlchemy for data persistence
- Redis for conversation history caching (24-hour TTL)
- FastAPI with gunicorn + uvicorn workers for production deployment
- Alembic for database migrations
Database Schema
- Users, conversations, health facilities, engagement metrics, knowledge assessments
- PostgreSQL enums for study groups, facility types, admin roles
AI Architecture
- System prompt engineered with WHO antenatal care guidelines and Kenya MOH protocols
- Dynamic gestational age context injection
- Conversation history (last 6 turns) from Redis
- Safety constraints for medical advice boundaries
Admin Dashboard
- JWT authentication with role-based access control
- Health facility management (CRUD operations)
- User analytics and data export (CSV/Excel)
- Emergency contact configuration per county
Infrastructure
- Docker Compose multi-container setup
- ngrok for webhook tunneling during development
- Non-root container users for security
- Deep health checks (DB + Redis)
Challenges we faced
Enum Serialization Bug: Pydantic 2.x wasn't serializing enum values correctly for PostgreSQL. Spent hours debugging why
StudyGroup.INTERVENTIONwas being passed as"INTERVENTION"instead of"intervention". Solution: Explicitly convert enums to their.valuein service layer.Emergency Response Timing: Initially, danger sign detection happened after AI generation, causing delays. Refactored to detect-first architecture for faster emergency alerts.
Database-Driven Facilities: Migrated from hardcoded hospital contacts to a flexible health facility database with county-based lookups, priority sorting, and verification flags.
Context Window Management: Balancing conversation history length (6 turns) with token limits while maintaining coherent responses.
Production Hardening: Securing the application for deployment—switching from development mode to gunicorn, adding non-root users, protecting admin endpoints, implementing pre-commit hooks for secret scanning.
What we learned
- Gemini 3 API capabilities: The
gemini-3-flash-previewmodel excels at generating medically accurate, culturally sensitive responses when given structured prompts - Prompt engineering for health: Careful system prompt design is critical for maintaining safety boundaries in medical advice
- Async Python at scale: SQLAlchemy async patterns, Redis caching strategies, and FastAPI dependency injection
- WhatsApp webhook patterns: Handling message deduplication, status callbacks, and retry logic
- Enum handling in SQLAlchemy + Pydantic: The nuances of PostgreSQL enum types with Python type systems
What's next for Zeya
- Voice message support using Gemini multimodal capabilities
- Proactive messaging with appointment reminders and weekly educational tips
- Integration with Kenya's DHIS2 for real-time facility bed availability
- Randomized controlled trial to measure impact on maternal health outcomes
- Expansion to other counties in Kenya and East Africa
- SMS fallback for users without WhatsApp
Built With
- alembic
- api
- asyncio
- cloud
- docker
- fastapi
- gemini
- gemini-3-flash-preview
- jwt
- postgresql
- pydantic
- python
- redis
- sqlalchemy
Log in or sign up for Devpost to join the conversation.