How kazol196295/medical_report_simplifier works
1. Purpose and Entry Point
This is a session-oriented Streamlit application that converts uploaded medical-report images into OCR text, AI explanations, report-grounded chat answers, and optional clinical-trial matches. The executable UI entry point is app.py; it coordinates all processing and stores transient interaction state in the Streamlit session.
Paths: app.py, .streamlit/config.toml, .streamlit/secrets.toml.example
2. Upload and OCR Boundary
Image uploads (JPG/PNG/JPEG/BMP) cross into the local OCR layer, which uses the host-installed Tesseract engine to produce raw report text. OCR is a material local-system dependency and the first transformation boundary: image bytes become text usable by every downstream feature.
Paths: app.py, src/ocr_tesseract.py, packages.txt
3. Report Analysis Agent
The conversational/analysis layer is modeled as a LangGraph state graph. It accepts OCR text, requested analysis mode, and conversation context; selects or invokes analysis tools; and generates explanatory medical content through Groq-hosted LLaMA 3.3-70B. Prompts and structured output expectations are separated from graph control flow.
Paths: src/langgraph_agent.py, src/tools.py, src/prompts.py
4. RAG Index and Report-Grounded Chat
Extracted text is indexed into a FAISS-backed retrieval layer using Hugging Face/Sentence Transformer embeddings. Follow-up chat retrieves semantically relevant report fragments before LLM response generation, creating a grounding boundary between report-specific evidence and the external model. The index is intended to be session-scoped rather than persistent user storage.
Paths: src/rag_engine.py, src/langgraph_agent.py, app.py
5. Patient Profile Extraction
For trial matching, OCR text is transformed into an editable structured patient profile: age, gender, diagnosis, biomarkers, and conditions. This is a separate AI extraction stage so users can review or correct uncertain OCR/LLM-derived fields before they drive external trial queries.
Paths: src/patient_profiler.py, src/prompts.py, app.py
6. Clinical-Trial Search and Matching
The approved profile is sent to the ClinicalTrials.gov API v2 client to find recruiting trials. Trial results are then evaluated for eligibility and presented with matched/unmet criteria. This stage crosses an external public-data boundary; it should tolerate unavailable or sparse API results independently of analysis/chat functionality.
Paths: src/clinical_trials_api.py, src/patient_profiler.py, src/tools.py
7. Runtime and External Dependencies
Runtime is Python 3.9+ with Streamlit as the UI server. Required external services are Groq (API key from Streamlit secrets, environment, or user entry) and ClinicalTrials.gov. Local infrastructure includes Tesseract plus native libraries, FAISS vector search, and model/embedding dependencies. Deployment is compatible with Streamlit Cloud, with OS packages declared separately.
Paths: requirements.txt, runtime.txt, packages.txt
Main entry points: langgraph_agent.py Analysis agent graph · app.py OCR report text · ocr_tesseract.py OCR layer · clinical_trials_api.py Trial search and matching
Components 18
Streamlit UI
- Application · Coordinates session-scoped report workflows.
app.py - Session state · Holds OCR text, chat context, and session index.
app.py - Uploaded report image
app.py - Python and deployment runtime · Streamlit, Python 3.9+, native packages, and Python dependencies.
requirements.txt
Report Processing
- OCR layer
src/ocr_tesseract.py - Tesseract · Host-installed image-to-text dependency.
packages.txt - OCR report text · Shared input for analysis, chat, and profiling.
app.py - Analysis agent graph · Routes analysis and conversational requests.
src/langgraph_agent.py - Analysis tools
src/tools.py - Prompts and schemas · Separates medical instructions and structured output expectations.
src/prompts.py - Report retrieval · Session-scoped semantic retrieval over report fragments.
src/rag_engine.py - Embedding models
src/rag_engine.py
Trial Matching
- Patient profile extraction · Produces editable demographics, diagnosis, biomarkers, and conditions.
src/patient_profiler.py - Reviewed patient profile · User-corrected input for trial queries.
app.py - Trial search and matching · Finds recruiting trials and evaluates criteria.
src/clinical_trials_api.py - Matched trial results · Includes matched and unmet criteria.
src/tools.py
External Services
- Groq LLaMA · Generates explanations and grounded answers.
- ClinicalTrials.gov API v2
Connections 21
- Uploaded report image → Application: upload
- Application → Session state: stores workflow state
- Application → OCR layer: submits image
- OCR layer → Tesseract: runs OCR
- OCR layer → OCR report text: extracts text
- OCR report text → Session state: retained per session
- OCR report text → Report retrieval: indexes fragments
- Embedding models → Report retrieval: embeds text and queries
- Session state → Analysis agent graph: analysis mode and chat context
- OCR report text → Analysis agent graph: report context
- Analysis agent graph → Report retrieval: retrieves chat evidence
- Analysis agent graph → Analysis tools: invokes tools
- Prompts and schemas → Analysis agent graph: instructions and output format
- Analysis agent graph → Groq LLaMA: generates response
- OCR report text → Patient profile extraction: extracts fields
- Prompts and schemas → Patient profile extraction: profile schema
- Patient profile extraction → Reviewed patient profile: user reviews and edits
- Reviewed patient profile → Trial search and matching: search criteria
- Trial search and matching → ClinicalTrials.gov API v2: queries recruiting trials
- Trial search and matching → Matched trial results: evaluates eligibility
- Python and deployment runtime → Application: hosts application