How coder360-crypto/btp works
Project type and purpose
• This is a command-line Medical Visual Question Answering (VQA) pipeline. It is not a web app or microservice suite; rather, it is a stand-alone Python framework that performs a sequence of image-and-question processing phases to produce medically-grounded answers without any model training.
• The README describes a 7-stage pipeline: ROI detection, focused image creation, concept extraction (via NVIDIA’s Gemma API), mechanistic grounding checks, knowledge-graph building, graph traversal, and answer synthesis.
File structure
• Top-level scripts:
• main.py – CLI entry point for single or batch processing.
• test_pipeline.py – Runs the same pipeline in a test or mock mode and writes evaluation metrics.
• Core code lives under src/:
• src/core/ – Implements pipeline phases (roi_detector.py, vqa_pipeline.py, etc.)
• src/graphs/knowledge_graph.py – Builds and traverses the medical knowledge graph.
• src/utils/ – Helper functions (image_utils.py, nlp_utils.py).
• src/visualization/ – Renders visual checks or metrics plots.
• src/data/ – Data ingestion or CSV helpers (if any).
• Config and requirements:
• .env / .env.example – Environment variables for API keys and thresholds.
• requirements.txt – Python dependencies.
README for additional insights
• Confirms the seven pipeline phases, describes configuration parameters, and shows the directory structure.
• Mentions that external service (NVIDIA Gemma 3-27B-IT) is invoked for concept extraction.
• Shows outputs: JSON answers, aggregated metrics, and visualizations.
a. Main components
1. CLI Interface (main.py / test_pipeline.py)
2. Configuration Loader (src/config.py + .env)
3. ROI Detector (src/core/roi_detector.py, uses image_utils.py)
4. Image Focusing (Gaussian blur module, part of roi_detector.py or utils)
5. Concept Extractor (src/core/concept_extractor.py) – calls NVIDIA Gemma VLM API
6. Grounding Checker (src/core/vqa_pipeline.py or within extractor)
7. Knowledge Graph Builder (src/graphs/knowledge_graph.py)
8. Graph Traversal & Answer Synthesizer (src/core/answer_synthesizer.py)
9. Visualization & Reporting (src/visualization/… + metric plots in outputs/)
10. Data Sink – writes JSON, CSV, visualizations to outputs/ or test_outputs/
b. Relationships & interactions
• CLI → loads Config → loops over each (image, question)
• → passes to ROI Detector → returns masked image + ROI metadata
• → Concept Extractor calls external VLM → returns raw concepts
• → Grounding Checker filters concepts → verified concepts
• → Graph Builder constructs a graph data structure
• → Graph Traverser queries graph using question semantics
• → Answer Synthesizer formats final answer
• → Reporter writes result JSON and, in test mode, passes answers to Metrics Evaluator → writes CSV/graphs.
c. Architectural patterns & principles
• Pipeline pattern: Each stage accepts input, processes, and emits to the next.
• Separation of concerns: Detection, extraction, grounding, graphing, synthesis are decoupled modules.
• Configdriven: .env + CLI flags control thresholds, model choice, and mode (mock/real).
• External integration: Clear boundary between internal logic and the NVIDIA Gemma API.
• Testable: test_pipeline.py allows mocking ROI and grounding.
d. Relevant technologies
• Python 3.8+
• NVIDIA Gemma 3-27B-IT (external VLM API)
• Spacy (for NLP preprocessing)
• NLTK (setup via setup_nltk.py)
• matplotlib/seaborn or similar (for visualizations)
• CSV / JSON file I/O
Elements
• Labels: Name each component exactly as in code (e.g., ROI Detector, Concept Extractor).
• Processing stages (rectangles in blue)
• Visualization / metrics (rectangles in purple)
Detailed capture of architectural elements
• Configuration injection at the top of pipeline.
• Utility libraries (image_utils, nlp_utils) as side dependencies feeding into ROI and extraction modules.
• Output directories (outputs/visualizations, test_outputs/graphs) as sinks.
1. Input Layer:
• CLI / Config
• Image & Question Source
2. Preprocessing & ROI:
• ROI Detector → Focused Image
3. Core Pipeline:
• Concept Extraction ↔ External VLM API
• Grounding Checker
• KnowledgeGraph Builder
• Graph Traversal & Answer Synthesizer
4. Output Layer:
• Answer JSON (outputs/)
• Visualizations (outputs/visualizations/)
• Test Metrics (test_outputs/)
5. Utility Modules (off to the side):
• image_utils, nlp_utils, spacy/NLTK setups
• config loader
• logging