How syt20/ai-powered-medical-report-simplifier works
Project type and purpose
• This is a backend-focused full-stack microservice (no separate UI) built with Python and FastAPI.
• It ingests scanned medical report images, runs OCR, then calls Google’s Gemini AI to structure and summarize test results.
File structure
• Top level:
• .env, requirements.txt, README.md – configuration and docs
• Data/ – sample input images
• app/ – application code
– main.py: FastAPI server entry point
– ocr.py: image preprocessing, Tesseract OCR, parsing, confidence scoring
– gemini_client.py: wraps calls to Google Gemini AI for structured extraction and summary
– models.py: Pydantic schemas for request/response models
• temp/ and outputs/ – folders for intermediate files and results
README for additional insights
• Processing pipeline described as:
Image Upload → Preprocessing → OCR Text Extraction → Data Filtering → AI Analysis → Structured Output
• Key technologies: FastAPI, Tesseract OCR, Google Gemini AI, Pydantic
Main components and numbered execution blocks
1. Client / API Gateway
• Receives HTTP POST /process-image
• Handles multipart/form-data upload
2. FastAPI Server (app/main.py)
• Validates request via Pydantic models (app/models.py)
• Orchestrates the pipeline
3. OCR Module (app/ocr.py)
3.1. Image Preprocessing (resizing, thresholding, denoising)
3.2. Tesseract OCR Text Extraction
3.3. Raw Text Parsing (extract lines, filter test entries)
3.4. Confidence Calculation
4. Gemini AI Client (app/gemini_client.py)
4.1. Structured Data Extraction (normalize test values into JSON)
4.2. Patient-Friendly Summary Generation
4.3. Medical Analysis (status: low/normal/high)
5. Data Models & Validation (app/models.py)
• Final Pydantic schemas for “step2”, “step3”, and “final” output
6. Response to Client
• Returns multi-stage JSON with steps 1–3 and combined “final”
• Tesseract OCR engine (local executable, configured via TESSERACT_CMD)
• Google Gemini API (requires GEMINI_API_KEY & MODEL)
Architectural patterns & design principles
• Modular separation: API layer, OCR layer, AI client layer, data validation layer
• Single responsibility per module
• Dependency injection of models into main controller
• External service abstraction (gemini_client)
• [ ] Number each block clearly (1, 2, 3.1, 3.2, …, 7)
• [ ] Indicate environment variables feeding into external services