How securdrgorp/cancercare-ai works
Project type and purpose
• This is a monolithic, full-stack web application built on Flask that exposes a REST/UI layer for AI-powered question answering in the cancer‐treatment domain.
• It combines a web frontend (HTML/CSS/JS/Chart.js) with a Python backend integrating several NLP/ML modules (BioBERT QA, sentence transformers, spaCy pipeline, data handlers) on local data files.
File structure
Top-level files & directories reveal an MVC-style separation:
• app.py: Flask app and route definitions (controllers).
• biobert_qa.py, context_provider.py, nlp_pipeline.py, data_handler.py: core service modules.
• data/: local CSV/JSON datasets (knowledge base).
• model/: locally stored BioBERT model.
• templates/: Jinja2 HTML views (index, chat, statistics, errors).
• static/: CSS/JS assets; Chart.js visualizations and custom script.
• scripts/saveModel.py: setup utility to download the BioBERT model.
• tests/: pytest suite covering each module and the Flask app.
README for insights
• Backend stack: Flask + Jinja2, BioBERT (PyTorch), Sentence Transformers, spaCy, Pandas/NumPy.
• Frontend stack: Bootstrap 5, Chart.js, custom JS for chat.
• Data flow: User → /api/chat or web pages → Flask routes → NLP pipeline + context provider → BioBERT QA engine → JSON/html response → user.
• No external DB: data lives in flat files.
Main components & interactions
a. Frontend (Browser)
• UI Views: index, chat, statistics (templates + static/js + static/css)
• Chart.js renders stats via GET /api/statistics
• AJAX POSTs to /api/chat
b. Web Server (Flask Application)
• Route controller layer (app.py)
• Error handling/logging
• Jinja2 template renderer
c. Service Modules (Python packages)
1. NLP Pipeline (nlp_pipeline.py)
– spaCy model loader, language detection, text normalization
2. Context Provider (context_provider.py)
– Loads knowledge base embeddings, performs semantic search
3. Data Handler (data_handler.py)
– Loads CSV/JSON, tabular data processing, statistics aggregation
4. BioBERT QA Engine (biobert_qa.py)
– Loads local BioBERT model files, runs extractive QA
d. Data Stores
• Local model directory (model/…)
• Flat files (data/*.csv, data/*.json)
e. External Dependencies (libraries)
– PyTorch/Transformers, SentenceTransformers, spaCy, pandas, NumPy
Relationships & data flows
• User → HTTP request → Flask route
• Flask route invokes:
• data_handler for any dashboard queries
• if chat: pass user text to nlp_pipeline → context_provider → biobert_qa → back up to Flask → JSON/html
• For statistics page: Flask → data_handler → Chart.js data payload
• All modules read from the same flat files; only BioBERT touches model directory.
Architectural patterns & design principles
• Layered architecture: UI layer, controller layer, service layer, data layer.
• Separation of concerns: each module has a single responsibility.
• No external database: file-based data storage.
• Synchronous request-response flow.
• Modular design to enable extensibility (e.g., swap in a new model).