How vishal88736/sanjeevani works
Purpose and Entry Points
Sanjeevani is a local FastAPI-served health-question assistant for major Indian languages. Users submit typed text or browser-recorded audio; the system returns a native-language transcript, English translation, and explicitly draft health guidance. The runtime entry point is website/backend/main.py (uvicorn website.backend.main:app); the browser client is static content rooted at website/frontend/index.html.
Web/API Boundary
The FastAPI backend serves the frontend and exposes request handling around typed and multipart audio inputs. Request/response contracts are centralized in website/backend/schemas.py, separating browser payloads from model-stage outputs. The frontend records audio with MediaRecorder, submits it to the backend, and renders pipeline results via website/frontend/assets/app.js.
Orchestration Pipeline
model/pipeline.py is the core application workflow coordinator. It selects the speech or text path, resolves the source language, translates to English when needed, retrieves clinical grounding context, then asks the LLM to draft the response. This is the main boundary between HTTP concerns and ML/provider integrations.
Speech Recognition and Language Resolution
model/asr/indic_asr.py wraps AI4Bharat IndicConformer for audio-to-native-language transcription. Explicit language selection supplies the decoder language; audio auto-detection instead transcribes against a short candidate set and uses plausibility heuristics to select a result. Typed text language detection is script-based and belongs to the pipeline/config-driven language model.
Translation Stage
model/translation/indic_translator.py wraps AI4Bharat IndicTrans2 to convert supported Indian-language text to English. English input bypasses translation. Language metadata and model-specific code mappings are defined centrally in model/config.py, which is the extension point for supported languages.
Answer Generation and Grounding Boundary
model/llm/groq_client.py is the sole adapter to Groq’s OpenAI-compatible LLM API. It receives English questions plus optional retrieved context and applies safety-oriented prompting: no diagnosis, encourage qualified health-worker consultation, and surface emergencies including India’s 108 service. model/llm/knowledge_base.py is intentionally a non-grounding placeholder; it currently returns no clinical context, so all answers remain drafts. Replacing its retrieval implementation is the primary production-clinical-data integration point.
Runtime, Models, and External Dependencies
The Python 3.11 service uses FastAPI/Uvicorn, with browser assets served locally. AI4Bharat checkpoints—IndicConformer and IndicTrans2—are downloaded from Hugging Face on first model use and cached locally. Groq requires GROQ_API_KEY from the process environment, read through model/config.py. Audio decoding relies on torchaudio; WebM/Opus recordings generally require system ffmpeg on PATH.
Main entry points: pipeline.py Question pipeline · main.py FastAPI service · indic_asr.py Indic ASR · groq_client.py Draft answer client
Components 15
Browser & API
- Browser client · Records audio, submits questions, and renders results.
website/frontend/index.html - Client behavior · Uses MediaRecorder and calls backend endpoints.
website/frontend/assets/app.js - FastAPI service · Serves static assets and accepts text or multipart audio.
website/backend/main.py - Request contracts · Separates browser payloads from pipeline outputs.
website/backend/schemas.py
ML Pipeline
- Question pipeline · Routes speech or text through language, translation, grounding, and drafting.
model/pipeline.py - Language configuration · Defines supported languages, code mappings, and runtime settings.
model/config.py - Indic ASR · Transcribes audio with explicit selection or candidate-based detection.
model/asr/indic_asr.py - Indic translation · Converts supported native-language text to English.
model/translation/indic_translator.py - Clinical context · Currently returns no context; intended retrieval integration point.
model/llm/knowledge_base.py - Draft answer client · Applies safety prompting and produces draft guidance.
model/llm/groq_client.py
Models & Providers
- IndicConformer checkpoint · Downloaded on first ASR use and cached locally.
- IndicTrans2 checkpoint · Downloaded on first translation use and cached locally.
- Groq API
- GROQ_API_KEY
- ffmpeg · Decodes typical WebM/Opus browser recordings.
Connections 16
- Browser client → Client behavior: loads
- Client behavior → FastAPI service: text or audio request
- FastAPI service → Request contracts: validates
- FastAPI service → Question pipeline: invokes
- Question pipeline → Language configuration: language metadata
- Question pipeline → Indic ASR: audio path
- Question pipeline → Indic translation: non-English text
- Question pipeline → Clinical context: retrieves context
- Question pipeline → Draft answer client: English question + context
- Indic ASR → IndicConformer checkpoint: transcribes with
- Indic ASR → ffmpeg: decodes audio via
- Indic translation → IndicTrans2 checkpoint: translates with
- Draft answer client → Groq API: OpenAI-compatible API
- Language configuration → GROQ_API_KEY: reads
- Draft answer client → GROQ_API_KEY: authenticates with
- Question pipeline → FastAPI service: transcript, translation, draft