Skip to content

Latest commit

 

History

History
143 lines (109 loc) · 6.28 KB

File metadata and controls

143 lines (109 loc) · 6.28 KB

Document Analyzer Pro

Overview

Document Analyzer Pro is a Streamlit-based web application that processes and analyzes documents (PDF, DOCX, TXT) using AI. The system extracts text from uploaded documents, generates comprehensive summaries, creates study questions, and produces interactive mind map visualizations using OpenAI's GPT models. The application includes admin authentication and stores document analysis results in a database for future reference.

User Preferences

Preferred communication style: Simple, everyday language.

System Architecture

Frontend Architecture

Problem: Need an intuitive interface for document upload and analysis visualization
Solution: Streamlit framework with custom CSS for a polished user experience
Rationale: Streamlit provides rapid development of data-driven applications with minimal frontend code. Custom CSS styling creates a professional gradient-based design with white content containers.

Key Design Decisions:

  • Wide layout mode for better utilization of screen space
  • Sidebar for navigation and controls
  • Custom purple gradient theme (#667eea to #764ba2)
  • Responsive containers with rounded corners and shadow effects

Backend Architecture

Problem: Process multiple document formats and generate AI-powered analysis
Solution: Modular Python architecture with separate concerns for authentication, document processing, AI analysis, and visualization

Core Modules:

  1. auth.py - Admin authentication using bcrypt password hashing
  2. document_processor.py - Text extraction from PDF (PyPDF2), DOCX (python-docx), and TXT files
  3. ai_analyzer.py - OpenAI GPT-5 integration for summary, question, and mind map generation
  4. mindmap_visualizer.py - Plotly-based interactive mind map rendering
  5. app.py - Main Streamlit application orchestrating all components

Architectural Pattern: Service-oriented with clear separation between data access, business logic, and presentation layers

Data Storage

Problem: Persist documents, analysis results, and user authentication
Solution: SQLAlchemy ORM with configurable database backend via DATABASE_URL environment variable

Database Schema:

  1. Admin Table:

    • id (Primary Key)
    • username (Unique, Indexed)
    • password_hash (bcrypt)
    • created_at (Timestamp)
  2. Documents Table:

    • id (Primary Key)
    • filename
    • file_type (pdf/docx/txt)
    • content (Full extracted text)
    • summary (AI-generated)
    • questions (JSON array of study questions)
    • mindmap_data (JSON structure for visualization)
    • uploaded_by (Admin username)
    • uploaded_at (Timestamp)

Design Decision: Store AI-generated content (summary, questions, mindmap_data) directly in the database to avoid regeneration costs and provide instant access to historical analyses.

Authentication & Authorization

Problem: Restrict document upload and management to authorized users
Solution: Password-based admin authentication with bcrypt hashing

Security Measures:

  • Bcrypt password hashing with automatic salt generation
  • Session-based authentication via Streamlit session state
  • Admin creation validation to prevent duplicate usernames

Trade-offs: Single-tier admin system (no role-based access control) provides simplicity suitable for small teams. Can be extended to multi-role system if needed.

AI Integration Architecture

Problem: Generate intelligent document analysis including summaries, questions, and mind maps
Solution: OpenAI GPT-5 API integration with structured prompting

Implementation Details:

  • Model: GPT-5 (as of August 7, 2025)
  • API Key: Environment variable (OPENAI_API_KEY)
  • Max tokens: 1000 for summaries, configurable for other operations
  • Response format: JSON for structured data (questions, mind maps)

Functions:

  1. generate_summary() - Comprehensive document summarization
  2. generate_questions() - 10 study questions as JSON array
  3. generate_mindmap_data() - Hierarchical structure with central topic and branches

Design Rationale: Direct API integration provides flexibility and access to latest model capabilities. Environment-based API key management ensures security.

Visualization Architecture

Problem: Present mind map data in an interactive, user-friendly format
Solution: Plotly graph objects for dynamic, web-based visualizations

Visualization Features:

  • Circular layout with central topic node
  • Branch nodes positioned radially around center
  • Subtopic nodes extending from branches
  • Interactive hover information
  • Color-coded nodes (central topic highlighted)
  • Responsive sizing and positioning

Technical Approach: Mathematical positioning using polar coordinates (angle_step calculation) to evenly distribute branches in a circle.

External Dependencies

AI & ML Services

  • OpenAI API (GPT-5): Primary AI engine for text analysis, summarization, question generation, and mind map creation
    • Authentication: API key via OPENAI_API_KEY environment variable
    • Critical dependency for core functionality

Database

  • SQLAlchemy: ORM for database abstraction
    • Connection: DATABASE_URL environment variable
    • Supports multiple database backends (PostgreSQL, MySQL, SQLite, etc.)
    • Database type not explicitly specified in code (runtime configuration)

Document Processing Libraries

  • PyPDF2: PDF text extraction
  • python-docx: Microsoft Word document processing
  • io: In-memory file handling for uploaded documents

Security

  • bcrypt: Password hashing and verification
    • Automatic salt generation
    • Industry-standard security for credential storage

Visualization & UI

  • Streamlit: Web application framework and UI components
  • Plotly: Interactive graph visualizations for mind maps
    • Uses graph_objects API for programmatic chart creation

Python Standard Libraries

  • os: Environment variable access
  • json: JSON parsing and serialization
  • datetime: Timestamp management
  • math: Geometric calculations for mind map positioning

Configuration Requirements

Two critical environment variables must be set:

  1. OPENAI_API_KEY: OpenAI API authentication
  2. DATABASE_URL: Database connection string

The application will raise ValueError exceptions if these are not configured, preventing runtime failures.