Skip to content

A web-based evaluation platform for OCR (Optical Character Recognition) results, featuring real-time leaderboard

Notifications You must be signed in to change notification settings

wcks13589/ocr-eval-platform

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

9 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

OCR Evaluation Platform

A web-based evaluation platform for OCR (Optical Character Recognition) results, featuring real-time leaderboard and TEDS (Tree Edit Distance based Similarity) metric scoring.

πŸ“‹ Overview

This platform allows users to:

  • Upload OCR prediction results in JSON format
  • Automatically evaluate predictions against ground truth using TEDS metrics
  • View real-time rankings on an interactive leaderboard with WebSocket progress updates
  • Analyze detailed evaluation results with filtering and statistics
  • Export results as CSV for further analysis
  • Switch between Traditional Chinese and English interfaces
  • Compare table recognition accuracy with other participants
  • Administrators can manage submissions and delete entries through a secure dashboard

πŸš€ Features

  • TEDS Metric: Industry-standard Tree Edit Distance based Similarity for table structure evaluation
  • Flexible Input: Supports both Markdown and HTML table formats
  • Real-time Leaderboard: Instant ranking updates after each submission
  • Detailed Score View: View individual table scores with filtering and statistics
  • WebSocket Progress: Real-time progress updates during evaluation
  • Multi-language Support: Switch between Traditional Chinese and English
  • Admin Dashboard: Manage submissions with authentication and delete capabilities
  • Format Validation: Automatic validation of uploaded JSON files
  • Modern UI: Clean and responsive web interface
  • Docker Support: Easy deployment with containerization
  • CSV Export: Download detailed scores as CSV files

πŸ› οΈ Tech Stack

  • Backend: FastAPI
  • Frontend: Jinja2 Templates, HTML/CSS/JavaScript
  • Real-time Communication: WebSocket
  • Internationalization: Custom i18n module (Chinese/English)
  • Metrics: TEDS (Tree Edit Distance), Levenshtein Distance, Edit Distance
  • Parsing: lxml, apted, distance, zss
  • Server: Uvicorn
  • Authentication: Cookie-based session management

πŸ“¦ Installation

Prerequisites

  • Python 3.12 or higher
  • pip package manager

Local Setup

  1. Clone the repository:
git clone https://github.com/wcks13589/ocr-eval-platform.git
cd ocr-eval-platform
  1. Install dependencies:
pip install -r requirements.txt
  1. Prepare your ground truth data:

    • Place your ground truth JSON file at data/ground_truth.json
    • Format: {"id": "<table>...</table>"} or markdown table format
  2. Run the server:

uvicorn app.main:app --host 0.0.0.0 --port 8080
  1. Access the platform:
    • Open your browser and navigate to http://localhost:8080

Docker Deployment

  1. Build the Docker image:
docker build -t ocr-eval-platform .
  1. Run the container with volume mounting:
docker run -p 8080:8080 \
  -v $(pwd)/data:/app/data \
  ocr-eval-platform

Note: The -v flag mounts the local data/ directory to persist uploads and leaderboard data.

  1. Access the platform at http://localhost:8080

Docker Compose (Recommended)

For easier management, use Docker Compose:

# Start the service
docker compose up -d

# View logs
docker compose logs -f

# Stop the service
docker compose down

The docker-compose.yml automatically handles volume mounting and configuration.

πŸ“ Usage

Preparing Prediction Files

Your prediction file should be a JSON file with the following structure:

{
  "sample_id_1": "| Header1 | Header2 |\n|---------|----------|\n| Cell1   | Cell2    |",
  "sample_id_2": "<table><tr><td>Cell1</td><td>Cell2</td></tr></table>",
  "sample_id_3": "..."
}

Supported formats:

  • Markdown tables
  • HTML table strings
  • Mixed format (different IDs can use different formats)

Submitting Predictions

  1. Navigate to the main page
  2. Enter your participant name
  3. Upload your JSON prediction file
  4. Click "Start Evaluation" (πŸš€ ι–‹ε§‹θ©•δΌ°)
  5. Watch real-time progress updates via WebSocket
  6. View your score and ranking on the leaderboard
  7. Click "Details" to see individual table scores

Viewing Detailed Results

After submission, you can view detailed evaluation results:

  1. Click the "πŸ” θ©³η΄°" (Details) button next to your name on the leaderboard
  2. View statistics including:
    • Overall TEDS score
    • Valid data count
    • Score distribution (Perfect/High/Medium/Low)
    • Individual table scores
  3. Use filters to show/hide:
    • Normal data (βœ…)
    • Missing data (❌)
    • Error data (⚠️)
    • Score range filtering
  4. Download results as CSV for further analysis

Admin Functions

Administrators can manage submissions:

  1. Navigate to /admin/login
  2. Enter the admin password
  3. Access the admin dashboard to:
    • View all submissions
    • Delete individual entries (removes all associated data)
    • Monitor platform usage
  4. Logout when finished to clear the session

Evaluation Metrics

The platform uses TEDS (Tree Edit Distance based Similarity) to evaluate table structure accuracy:

  • Range: 0.0 to 1.0 (higher is better)
  • Calculation: Measures structural and content similarity between predicted and ground truth tables
  • Normalization: Accounts for table size differences
  • Weighting: Considers both cell content and table structure

πŸ“Š API Endpoints

Public Endpoints

GET /

Main page with upload form and leaderboard

POST /upload

Upload prediction file without evaluation

  • Parameters:
    • name (form field): Participant name
    • file (file upload): JSON prediction file
  • Returns: JSON response with file path or error

POST /evaluate

Upload and evaluate prediction file (fallback for non-WebSocket)

  • Parameters:
    • name (form field): Participant name
    • file (file upload): JSON prediction file
  • Returns: Updated leaderboard with evaluation results

GET /leaderboard

View standalone leaderboard page

GET /details/{name}

View detailed evaluation results for a participant

  • Parameters:
    • name (path): Participant name
  • Returns: HTML page with detailed scores, statistics, and filtering options

GET /api/details/{name}

Get detailed evaluation data in JSON format

  • Parameters:
    • name (path): Participant name
  • Returns: JSON with detailed scores and statistics

GET /set_language/{lang}

Set interface language preference

  • Parameters:
    • lang (path): Language code (zh-TW or en)
  • Returns: Redirect to previous page with language cookie set

WebSocket /ws/{session_id}

Real-time evaluation progress updates

  • Parameters:
    • session_id (path): Unique session identifier
  • Messages:
    • Receives: {name, file_path} to start evaluation
    • Sends: Progress updates and completion status

Admin Endpoints

GET /admin/login

Admin login page

POST /admin/login

Admin authentication

  • Parameters:
    • password (form field): Admin password
  • Returns: Redirect to dashboard on success

GET /admin/dashboard

Admin control panel (requires authentication)

  • Features: View all submissions, delete entries
  • Authentication: Cookie-based session token

POST /admin/logout

Admin logout and session cleanup

DELETE /api/admin/delete/{name}

Delete a participant's data (requires admin authentication)

  • Parameters:
    • name (path): Participant name
    • admin_token (cookie): Admin session token
  • Returns: JSON response with updated leaderboard

πŸ—‚οΈ Project Structure

ocr-eval-platform/
β”œβ”€β”€ app/
β”‚   β”œβ”€β”€ main.py              # FastAPI application and routes
β”‚   β”œβ”€β”€ evaluation.py        # Evaluation logic and metrics
β”‚   β”œβ”€β”€ TEDS_metric.py       # TEDS implementation
β”‚   β”œβ”€β”€ parallel.py          # Parallel processing utilities
β”‚   β”œβ”€β”€ i18n.py              # Internationalization (Chinese/English)
β”‚   β”œβ”€β”€ static/
β”‚   β”‚   └── style.css        # Styling
β”‚   └── templates/
β”‚       β”œβ”€β”€ index.html       # Main page with upload form
β”‚       β”œβ”€β”€ leaderboard.html # Standalone leaderboard page
β”‚       β”œβ”€β”€ details.html     # Detailed score view page
β”‚       β”œβ”€β”€ admin_login.html # Admin login page
β”‚       β”œβ”€β”€ admin_dashboard.html # Admin control panel
β”‚       └── result.html      # Results display (legacy)
β”œβ”€β”€ data/                    # Data directory (separate from code)
β”‚   β”œβ”€β”€ ground_truth.json    # Ground truth data
β”‚   β”œβ”€β”€ leaderboard.json     # Leaderboard storage (auto-generated)
β”‚   β”œβ”€β”€ details/             # Individual participant detailed scores
β”‚   └── uploads/             # Uploaded prediction files
β”œβ”€β”€ .gitignore              # Git ignore rules
β”œβ”€β”€ Dockerfile              # Docker configuration
β”œβ”€β”€ docker-compose.yml      # Docker Compose configuration
β”œβ”€β”€ requirements.txt        # Python dependencies
└── README.md              # This file

πŸ”§ Configuration

Data Management

The platform uses a dedicated data/ directory to separate data from code:

Benefits:

  • βœ… Clean separation: Code and data are isolated
  • βœ… Easy backup: Simply backup the data/ folder
  • βœ… Docker persistence: Easy volume mounting for containers
  • βœ… Version control: Data files can be gitignored separately
  • βœ… Security: Sensitive data isolated from application code

Directory structure:

data/
β”œβ”€β”€ ground_truth.json    # Your test dataset (required)
β”œβ”€β”€ leaderboard.json     # Auto-generated rankings
β”œβ”€β”€ details/             # Detailed scores for each participant
└── uploads/             # User-submitted predictions

Ground Truth Format

The data/ground_truth.json file should contain:

{
  "sample_id_1": "| Header1 | Header2 |\n|---------|----------|\n| Cell1   | Cell2    |",
  "sample_id_2": "<table><tr><td>Cell1</td><td>Cell2</td></tr></table>",
  "sample_id_3": "..."
}

Example with actual data:

{
  "table_001": "| Name | Age | City |\n|------|-----|------|\n| Alice | 30 | NYC |",
  "table_002": "<table><tr><td>Product</td><td>Price</td></tr><tr><td>Apple</td><td>$2</td></tr></table>"
}

Admin Configuration

Set the admin password using an environment variable:

# Linux/Mac
export ADMIN_PASSWORD="your_secure_password"

# Windows
set ADMIN_PASSWORD=your_secure_password

# Docker
docker run -p 8080:8080 -e ADMIN_PASSWORD=your_secure_password ocr-eval-platform

Default password (if not set): admin123

Security Note: Always change the default admin password in production environments.

Language Settings

The platform supports:

  • Traditional Chinese (zh-TW) - Default
  • English (en)

Users can switch languages using the language selector in the web interface. The preference is stored in a cookie for 1 year.

Modifying TEDS Parameters

In app/evaluation.py, you can adjust:

teds = TEDS(n_jobs=4)  # Number of parallel jobs

πŸ› Error Handling

The platform handles various error cases:

  • Invalid JSON format: Returns error message with parsing details and removes uploaded file
  • Encoding errors: Detects non-UTF-8 files and provides helpful error messages
  • Duplicate names: Prevents overwriting existing submissions with clear warning
  • Missing fields: Gracefully handles incomplete predictions
  • WebSocket fallback: Automatically falls back to traditional POST if WebSocket is unavailable
  • Authentication errors: Redirects to login page for unauthorized admin access
  • File cleanup: Automatically removes uploaded files on evaluation failure

πŸ“„ License

Copyright 2020 IBM (TEDS implementation)
Licensed under Apache 2.0 License

🀝 Contributing

Contributions are welcome! Please feel free to submit issues or pull requests.

πŸ“ž Support

For questions or issues, please contact the project maintainer or open an issue on GitHub.

πŸ™ Acknowledgments

  • TEDS implementation based on PubTabNet by IBM Research
  • Tree edit distance using apted library
  • FastAPI framework for rapid web development

Version: 2.0.0
Last Updated: October 2025

πŸ†• What's New in v2.0.0

  • ✨ Multi-language support (Traditional Chinese and English)
  • πŸ” Admin dashboard with authentication
  • πŸ“Š Detailed score view with filtering and statistics
  • 🌐 WebSocket real-time progress updates
  • πŸ“₯ CSV export functionality
  • πŸ—‘οΈ Admin delete capabilities
  • 🎨 Improved UI with better user experience
  • πŸ”’ Cookie-based session management

About

A web-based evaluation platform for OCR (Optical Character Recognition) results, featuring real-time leaderboard

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published