Team Ai
Apppublic

ahsananwar102/MedReport-Explainer

sourceHugging Faceupdated 1y agoView on Hugging Face
0likes
App README

๐Ÿฅ 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

  1. 1.Go to Groq Console
  2. 2.Sign up for a free account
  3. 3.Create a new API key
  4. 4.Copy the API key for deployment

2. Deploy to Hugging Face Spaces

  1. 1.Create a new Space:
  2. 2.Go to Hugging Face Spaces
  3. 3.Click "Create new Space"
  4. 4.Choose "Docker" as the SDK
  5. 5.Set visibility (public/private)
  1. 1.Upload files:
  2. 2.Upload all project files to your Space
  3. 3.Ensure Dockerfile is in the root directory
  1. 1.Set environment variables:
  2. 2.In your Space settings, add:
  3. 3.GROQ_API_KEY: Your Groq API key
  1. 1.Deploy:
  2. 2.The Space will automatically build using the Dockerfile
  3. 3.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:

python
# 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

  1. 1.Upload a medical report (PDF, TXT, or DOCX)
  2. 2.Choose reading level (12-year-old or 8th-grade)
  3. 3.Review extracted sections and highlighted complex terms
  4. 4.Generate summary for easy understanding
  5. 5.Ask questions about specific terms or conditions
  6. 6.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

  1. 1.API Key Error
   Error: GROQ_API_KEY environment variable not set

Solution: Set your Groq API key in Hugging Face Space settings

  1. 1.Docker Build Issues
   Build timeout or memory errors

Solution: The Dockerfile is optimized for Hugging Face Spaces limits

  1. 1.File Upload Issues
   Error: Unsupported format

Solution: Use PDF, TXT, or DOCX files under 10MB

๐Ÿค Contributing

  1. 1.Fork the repository
  2. 2.Create feature branch (git checkout -b feature/amazing-feature)
  3. 3.Commit changes (git commit -m 'Add amazing feature')
  4. 4.Push to branch (git push origin feature/amazing-feature)
  5. 5.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.