ahsananwar102/MedReport-Explainer
0
๐ฅ Medical Report Explainer
An AI-powered web application that helps users understand medical reports through intelligent explanations, summaries, and Q&A functionality using RAG (Retrieval-Augmented Generation) and Groq API.
โจ Features
- ๐ Document Upload: Support for PDF, TXT, and DOCX medical reports
- ๐ Text Extraction: Advanced extraction with fallback methods for complex documents
- ๐ RAG System: Retrieval-Augmented Generation using medical corpus (PubMed + Mayo Clinic)
- ๐ง AI Explanations: Groq-powered explanations at different reading levels (ultra-fast inference)
- ๐ Smart Summaries: Generate patient-friendly summaries
- โ Interactive Q&A: Ask questions about medical terms and conditions
- ๐ท๏ธ Term Highlighting: Identify and explain complex medical terminology
- ๐ Feedback System: User feedback collection and analytics
- โ ๏ธ Medical Disclaimer: Prominent medical disclaimers and safety warnings
๐ ๏ธ Tech Stack
- Frontend: Streamlit
- Backend: Python 3.10+
- Vector Store: FAISS for similarity search
- Embeddings: Sentence-BERT (all-MiniLM-L6-v2)
- LLM: Groq API (ultra-fast inference with Llama3-70B)
- Document Processing: PyMuPDF, python-docx
- Data Sources: PubMed (via Entrez API), Mayo Clinic articles
- Deployment: Docker + Hugging Face Spaces
๐ Quick Start
1. Get Groq API Key
- Go to Groq Console
- Sign up for a free account
- Create a new API key
- Copy the API key for deployment
2. Deploy to Hugging Face Spaces
- Create a new Space:
- Go to Hugging Face Spaces
- Click "Create new Space"
- Choose "Docker" as the SDK
- Set visibility (public/private)
- Upload files:
- Upload all project files to your Space
- Ensure
Dockerfileis in the root directory
- Set environment variables:
- In your Space settings, add:
GROQ_API_KEY: Your Groq API key
- Deploy:
- The Space will automatically build using the Dockerfile
- Build time: ~10-15 minutes for first deployment
๐ Project Structure
medreport_explainer/
โโโ Dockerfile # Docker configuration for deployment
โโโ .dockerignore # Files to exclude from Docker build
โโโ streamlit_app.py # Main Streamlit application
โโโ app.py # Entry point for Hugging Face Spaces
โโโ requirements.txt # Python dependencies (optimized)
โโโ README.md # This file
โโโ config/
โ โโโ __init__.py
โ โโโ config.py # Configuration settings
โโโ src/
โ โโโ __init__.py
โ โโโ data_ingestion.py # PubMed & Mayo Clinic data download
โ โโโ document_processor.py # PDF/TXT/DOCX text extraction
โ โโโ embeddings.py # FAISS vector store & embeddings
โ โโโ llm_integration.py # Google Gemini integration
โโโ utils/
โ โโโ __init__.py
โ โโโ feedback.py # User feedback management
โโโ data/ # Data storage (created at runtime)
โโโ corpus/ # Medical corpus storage
โโโ embeddings/ # FAISS index files
โโโ feedback.json # User feedback data๐ง Configuration
Key configuration options in config/config.py:
# API Settings
GROQ_API_KEY = os.getenv("GROQ_API_KEY")
GROQ_MODEL = "llama3-70b-8192" # Fast Groq model
# Embedding Settings
EMBEDDING_MODEL = "all-MiniLM-L6-v2" # Lightweight model
EMBEDDING_DIMENSION = 384
CHUNK_SIZE = 500
CHUNK_OVERLAP = 50
# File Processing
MAX_FILE_SIZE = 10 * 1024 * 1024 # 10MB
SUPPORTED_FORMATS = [".pdf", ".txt", ".docx"]๐ Usage
Basic Workflow
- Upload a medical report (PDF, TXT, or DOCX)
- Choose reading level (12-year-old or 8th-grade)
- Review extracted sections and highlighted complex terms
- Generate summary for easy understanding
- Ask questions about specific terms or conditions
- Provide feedback to improve the system
Reading Levels
- 12-year-old: Very simple language, short sentences, no medical jargon
- 8th-grade: Clear language with medical terms explained in parentheses
๐ก๏ธ Safety & Disclaimers
This application includes comprehensive medical disclaimers and safety warnings:
- โ ๏ธ Educational purposes only - Not medical advice
- ๐จโโ๏ธ Always consult healthcare professionals for medical decisions
- ๐จ Emergency situations - Contact emergency services immediately
- ๐ Information limitations - May not apply to specific situations
๐ Data Sources
Medical Corpus
- PubMed: Medical literature abstracts via Entrez API
- Mayo Clinic: Disease and condition articles
- Processing: Chunked and embedded for RAG retrieval
Privacy
- No patient data is stored permanently
- Feedback is stored locally and anonymized
- API calls to Gemini follow Google's privacy policies
๐ Troubleshooting
Common Issues
- API Key Error
Error: GROQ_API_KEY environment variable not setSolution: Set your Groq API key in Hugging Face Space settings
- Docker Build Issues
Build timeout or memory errorsSolution: The Dockerfile is optimized for Hugging Face Spaces limits
- File Upload Issues
Error: Unsupported formatSolution: Use PDF, TXT, or DOCX files under 10MB
๐ค Contributing
- Fork the repository
- Create feature branch (
git checkout -b feature/amazing-feature) - Commit changes (
git commit -m 'Add amazing feature') - Push to branch (
git push origin feature/amazing-feature) - Open a Pull Request
๐ License
This project is licensed under the MIT License.
๐ Acknowledgments
- Groq for ultra-fast AI inference
- Hugging Face for hosting platform
- PubMed/NCBI for medical literature access
- Mayo Clinic for patient education resources
- Streamlit for the web framework
โ ๏ธ Important: This tool is for educational purposes only. Always consult qualified healthcare professionals for medical advice, diagnosis, and treatment decisions.
