CoolFace
Apppublic

pratikmurali/FDA_Regulatory_Assistant_For_SaMD

sourceHugging Faceapache-2.0updated 1y agoView on Hugging Face
0likes
App README

FDA Regulatory Assistant

A sophisticated AI-powered assistant for FDA regulatory compliance analysis, built with LangGraph multi-agent workflows and Chainlit for an interactive user experience.

๐Ÿš€ Features

๐Ÿค– Multi-Agent System

  • โ€”Supervisor Agent: Intelligent routing and response compilation as FDA auditor
  • โ€”Document Processor: Advanced ZIP file extraction and document parsing
  • โ€”Cybersecurity Specialist: FDA cybersecurity guidance and SOUP documentation analysis
  • โ€”Regulatory Affairs Expert: CFR510K, PMA, and FDA regulatory compliance review
  • โ€”Compliance Auditor: FDA Auditor like, Comprehensive gap analysis and readiness assessment
  • โ€”Report Generator: Detailed compliance reports with actionable recommendations

๐Ÿ’ฌ Interactive Capabilities

  • โ€”Intelligent Q&A: Context-aware routing to appropriate specialist agents
  • โ€”Document Gap Analysis: Upload ZIP files containing regulatory submission packages
  • โ€”Real-time Streaming: Word-by-word response streaming with agent identification
  • โ€”Source References: All responses include original FDA document citations
  • โ€”File Processing: Support for PDF, Word, TXT, and ZIP file uploads

๐Ÿ—๏ธ Advanced Architecture

  • โ€”Simplified LangGraph Workflow: Clean state management with message passing
  • โ€”24+ Specialized Tools: Comprehensive toolkit for document processing and compliance analysis
  • โ€”RAG Integration: Pre-warmed chains for instant access to FDA knowledge base
  • โ€”Streaming Configuration: Customizable streaming speeds and formatting preservation
  • โ€”Error Handling: Graceful degradation and comprehensive error reporting

๐Ÿ› ๏ธ Technology Stack

  • โ€”Multi-Agent Framework: LangGraph with simplified state management
  • โ€”UI Framework: Chainlit for interactive chat interface with file uploads
  • โ€”LLM: OpenAI GPT-4o-mini with function calling
  • โ€”Vector Database: Qdrant for efficient knowledge base storage and retrieval
  • โ€”Document Processing: PyMuPDF (fitz) for PDF parsing, python-docx for Word documents
  • โ€”RAG System: Custom chain manager with pre-warming and caching
  • โ€”Package Management: UV for fast, reliable dependency management
  • โ€”Testing: Pytest with comprehensive test suite
  • โ€”Code Quality: Ruff for linting and code formatting
  • โ€”Tracing: LangSmith for monitoring and debugging
  • โ€”Offline Evals: RAGA for offline evaluation and testing

๐Ÿ“‹ Prerequisites

  • โ€”Python 3.12+
  • โ€”OpenAI API key
  • โ€”UV package manager (recommended) or pip

๐Ÿ”ง Installation

  1. 1.Clone the repository
bash
   git clone <repository-url>
   cd fda-regulatory-assistant
  1. 1.Install dependencies
bash
   # Using UV (recommended)
   uv sync

   # Or using pip
   pip install -r requirements.txt
  1. 1.Set up environment variables
bash
   cp .env.example .env
   # Edit .env and add your OpenAI API key
   OPENAI_API_KEY=your_api_key_here
  1. 1.Initialize the knowledge base (if needed)
bash
   python setup_env.py

๐Ÿš€ Usage

Start the Application

bash
chainlit run main.py -w

The application will be available at http://localhost:8000

Using the Assistant

Question Answering

Simply ask questions about FDA regulations or cybersecurity requirements:

  • โ€”"What are the FDA cybersecurity requirements for medical devices?"
  • โ€”"How do I submit a 510(k) application?"
  • โ€”"What are the SOUP requirements for medical device software?"
Document Analysis
  1. 1.Upload documents (PDF, TXT, or ZIP files)
  2. 2.Ask for compliance gap analysis
  3. 3.Receive detailed reports with findings and recommendations

Example Interactions

Cybersecurity Question:

User: What are the key cybersecurity controls for Class II medical devices?
Assistant: Based on FDA guidance, Class II medical devices should implement...

Gap Analysis:

User: [Uploads device specification PDF]
User: Please analyze this document for regulatory compliance gaps
Assistant: **Cybersecurity Agent**: Analyzing cybersecurity compliance...
**Regulatory Agent**: Reviewing regulatory requirements...
**Auditor Agent**: Performing gap analysis...
**Report Generator**: Generating comprehensive report...

๐Ÿ“ Project Structure

fda-regulatory-assistant/
โ”œโ”€โ”€ main.py                     # Chainlit application entry point
โ”œโ”€โ”€ graph/                      # LangGraph multi-agent workflow
โ”‚   โ”œโ”€โ”€ agents.py              # 6 specialized agents with tool bindings
โ”‚   โ”œโ”€โ”€ graph.py               # Workflow orchestration and streaming
โ”‚   โ””โ”€โ”€ state.py               # Simplified state management
โ”œโ”€โ”€ tools/                      # Comprehensive agent toolkit (24+ tools)
โ”‚   โ”œโ”€โ”€ __init__.py            # Tool exports
โ”‚   โ”œโ”€โ”€ tools.py               # Core tool implementations
โ”‚   โ”œโ”€โ”€ README.md              # Tool documentation
โ”‚   โ””โ”€โ”€ example_usage.py       # Usage examples
โ”œโ”€โ”€ ragchains/                  # RAG chain implementations
โ”‚   โ”œโ”€โ”€ chain_manager.py       # Centralized chain management
โ”‚   โ”œโ”€โ”€ fda_cybersecurity_rag.py # Cybersecurity knowledge base
โ”‚   โ”œโ”€โ”€ fda_regulatory_rag.py  # Regulatory knowledge base
โ”‚   โ””โ”€โ”€ tools/                 # Legacy tool compatibility
โ”œโ”€โ”€ utils/                      # Utility functions
โ”‚   โ”œโ”€โ”€ document_parsers.py    # Advanced document processing
โ”‚   โ”œโ”€โ”€ streaming_config.py    # Streaming configuration
โ”‚   โ””โ”€โ”€ langgraph_utils.py     # LangGraph helper functions
โ”œโ”€โ”€ prompts/                    # LLM prompts and templates
โ”œโ”€โ”€ tests/                      # Comprehensive test suite
โ”œโ”€โ”€ examples/                   # Usage examples and demos
โ”œโ”€โ”€ loaders/                    # Document loaders
โ””โ”€โ”€ pyproject.toml             # UV package configuration

๐Ÿ”„ Workflow Architecture

The application implements a simplified LangGraph multi-agent system with intelligent routing and streaming responses:

๐ŸŽฏ Workflow Types

1. Question Answering Flow

User Question โ†’ Supervisor โ†’ Route to Specialist โ†’ Tool Execution โ†’ Streaming Response

2. Gap Analysis Flow

ZIP Upload โ†’ Document Processor โ†’ Cybersecurity Agent โ†’
Regulatory Agent โ†’ Auditor Agent โ†’ Report Generator โ†’ Final Report

๐Ÿง  Agent Specialization

  1. 1.Supervisor Agent:
  2. 2.Intelligent routing based on question keywords
  3. 3.Final response compilation as FDA auditor
  4. 4.Workflow orchestration and error handling
  1. 1.Document Processor:
  2. 2.ZIP file extraction and validation
  3. 3.Multi-format document parsing (PDF, Word, TXT)
  4. 4.Document chunking and metadata extraction
  1. 1.Cybersecurity Specialist:
  2. 2.FDA cybersecurity guidance analysis
  3. 3.SOUP (Software of Unknown Provenance) documentation
  4. 4.Vulnerability assessment and security controls
  1. 1.Regulatory Affairs Expert:
  2. 2.510K submission requirements
  3. 3.PMA and regulatory compliance
  4. 4.FDA guidance interpretation
  1. 1.Compliance Auditor:
  2. 2.Gap analysis and readiness assessment
  3. 3.Compliance scoring and prioritization
  4. 4.Risk assessment and mitigation
  1. 1.Report Generator:
  2. 2.Comprehensive compliance reports
  3. 3.Executive summaries and recommendations
  4. 4.Actionable improvement plans

๐Ÿ”ง Key Architecture Features

  • โ€”Simplified State: TypedDict with message passing using operator.add
  • โ€”Tool Integration: 24+ specialized tools for document processing and analysis
  • โ€”Streaming Support: Real-time word-by-word response streaming
  • โ€”Error Handling: Graceful degradation with recursion limits
  • โ€”Source References: Automatic extraction and formatting of source citations
  • โ€”Pre-warmed Chains: Instant response times through chain pre-loading

๐Ÿงช Testing

Run the test suite:

bash
# Run all tests
python -m pytest tests/

# Run specific test categories
python -m pytest tests/test_streaming_*.py
python -m pytest tests/test_tools_integration.py

๐Ÿ“Š Performance Features

๐Ÿš€ Optimized Performance

  • โ€”Pre-warmed RAG Chains: Instant response times after startup initialization
  • โ€”Streaming Responses: Real-time word-by-word streaming with configurable delays
  • โ€”Concurrent Processing: Thread-safe multi-agent execution
  • โ€”Memory Efficiency: Shared vector stores and optimized document processing
  • โ€”Caching: Intelligent caching of frequently accessed regulatory information

๐Ÿ“ˆ Scalability Features

  • โ€”Session Isolation: Independent user sessions with shared resources
  • โ€”Error Recovery: Graceful degradation and automatic retry mechanisms
  • โ€”Resource Management: Automatic cleanup and garbage collection
  • โ€”Load Balancing: Efficient distribution of agent workloads

๐Ÿ”ง Configuration

Environment Variables

bash
# Required
OPENAI_API_KEY=your_api_key_here

# Optional
CHAINLIT_AUTH_SECRET=your_secret_here
LANGSMITH_API_KEY=your_langsmith_key  # For tracing

Streaming Configuration

Customize streaming behavior in utils/streaming_config.py:

python
# Streaming modes
STREAMING_MODE = "word"  # Options: "character", "word", "sentence"
WORD_DELAY = 0.05       # 50ms delay between words
ADAPTIVE_STREAMING = True  # Adjust speed based on content

# Speed presets
SPEED_PRESETS = {
    "instant": 0.0,
    "fast": 0.005,
    "normal": 0.01,
    "slow": 0.02
}

Agent Configuration

Customize agent behavior in graph/agents.py:

python
# Routing keywords for intelligent agent selection
CYBERSECURITY_KEYWORDS = ["cybersecurity", "SOUP", "vulnerability", "security"]
REGULATORY_KEYWORDS = ["510k", "PMA", "regulatory", "submission"]
AUDITOR_KEYWORDS = ["gap", "analysis", "compliance", "audit"]

Tool Configuration

Adjust tool parameters in tools/tools.py:

python
# Document processing settings
DEFAULT_CHUNK_SIZE = 1000
DEFAULT_CHUNK_OVERLAP = 80

# Compliance thresholds
COMPLIANCE_THRESHOLDS = {
    "critical": 0.9,
    "major": 0.7,
    "minor": 0.5
}

๐Ÿค Contributing

  1. 1.Fork the repository
  2. 2.Create a feature branch (git checkout -b feature/amazing-feature)
  3. 3.Commit your changes (git commit -m 'Add amazing feature')
  4. 4.Push to the branch (git push origin feature/amazing-feature)
  5. 5.Open a Pull Request

๐Ÿ“ License

This project is licensed under the MIT License - see the LICENSE file for details.

๐Ÿ†˜ Support

For questions or issues:

  1. 1.Check the Issues page
  2. 2.Review the test files for usage examples
  3. 3.Consult the architecture documentation in ARCHITECTURE.md

๐Ÿ”ฎ Roadmap

๐ŸŽฏ Near-term Enhancements

  • โ€”[ ] Enhanced Document Support: Excel, PowerPoint, and additional file formats
  • โ€”[ ] Advanced Analytics: Compliance trend analysis and historical tracking
  • โ€”[ ] Batch Processing: Multiple document package analysis
  • โ€”[ ] Custom Templates: User-defined compliance checklists and report formats

๐Ÿš€ Future Features

  • โ€”[ ] FDA Database Integration: Real-time access to FDA guidance updates
  • โ€”[ ] Visualization Dashboard: Interactive compliance dashboards and charts
  • โ€”[ ] Multi-language Support: Support for international regulatory frameworks
  • โ€”[ ] API Integration: RESTful API for enterprise integration
  • โ€”[ ] Advanced AI Features: Predictive compliance analysis and risk scoring

๐Ÿ”ง Technical Improvements

  • โ€”[ ] Performance Optimization: Enhanced caching and parallel processing
  • โ€”[ ] Security Enhancements: Advanced authentication and data encryption
  • โ€”[ ] Monitoring & Observability: Comprehensive logging and metrics
  • โ€”[ ] Deployment Options: Docker containers and cloud deployment guides

Built with โค๏ธ using LangGraph, Chainlit, OpenAI, and PyMuPDF

Empowering regulatory compliance through intelligent multi-agent systems