Skip to content

akshay2172/Graph_Data_Extractor

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Graph Data Extractor

A web application that extracts numerical data points from graph images using OpenAI Vision API. Upload images of graphs (line plots, scatter plots, etc.) and get the data exported to CSV and Excel formats.

Features

  • Image Upload: Support for PNG, JPG, JPEG, and PDF graph images
  • AI-Powered Extraction: Uses OpenAI GPT-4o-mini via OpenRouter to analyze graphs and extract data points
  • Accurate Coordinate System: Extracts data using graph coordinates (axes intersection as origin) rather than image pixel positions
  • Multiple Output Formats: Downloads data as CSV and Excel files
  • Web Interface: Simple drag-and-drop upload interface
  • API Endpoint: REST API for programmatic access
  • Graph Type Detection: Automatically detects graph types or accepts manual specification
  • Axis Labeling: Supports custom X and Y axis labels

Requirements

  • Python 3.8+
  • OpenRouter API key (for OpenAI Vision access)
  • Flask
  • OpenAI Python client
  • Pandas
  • Other dependencies listed in req.txt

Installation

  1. Clone or download this repository:

    git clone <repository-url>
    cd graph_data_extractor
  2. Install dependencies:

    pip install -r req.txt
  3. Create a .env file in the root directory with your API keys:

    OPENROUTER_API_KEY=your_openrouter_api_key_here
    FLASK_SECRET_KEY=your_secret_key_here
    
  4. Run the application:

    python app.py
  5. Open your browser and navigate to http://localhost:5000

Usage

Web Interface

  1. Open the application in your browser
  2. Upload a graph image by dragging and dropping or clicking to select
  3. Optionally specify graph type, X-axis label, and Y-axis label
  4. Click "Extract Data" to process the image
  5. Download the extracted data as CSV or Excel files

API Usage

Send a POST request to /api/extract with JSON payload:

{
  "image": "data:image/png;base64,<base64-encoded-image>",
  "graph_type": "linear",
  "x_label": "Time",
  "y_label": "Value"
}

Response format:

{
  "graph_type": "linear",
  "x_axis": {"label": "Time", "unit": "s"},
  "y_axis": {"label": "Value", "unit": "V"},
  "data_points": [
    {"x": 1.0, "y": 2.5, "uncertainty": 0.1},
    {"x": 2.0, "y": 3.2, "uncertainty": 0.1}
  ],
  "summary": {
    "total_points": 2,
    "x_range": [1.0, 2.0],
    "y_range": [2.5, 3.2],
    "confidence": 0.95,
    "notes": []
  }
}

API Endpoints

  • GET /: Main web interface
  • POST /upload: File upload endpoint (used by web interface)
  • POST /api/extract: Direct API for data extraction
  • GET /download/<filename>: Download extracted data files

Configuration

  • Upload Folder: Files are temporarily stored in uploads/ directory
  • Max File Size: 16MB limit per upload
  • Supported Formats: PNG, JPG, JPEG, PDF

Environment Variables

  • OPENROUTER_API_KEY: Required for OpenAI Vision API access
  • FLASK_SECRET_KEY: Secret key for Flask sessions (optional, defaults to dev key)

How It Works

  1. Image Processing: Uploaded images are encoded and sent to OpenAI Vision API
  2. AI Analysis: The AI analyzes the graph, identifies axes, and extracts data points using graph coordinates
  3. Data Extraction: Points are measured relative to the graph origin (axes intersection)
  4. Output Generation: Extracted data is formatted into CSV and Excel files for download

Troubleshooting

  • API Key Issues: Ensure your OpenRouter API key is valid and has sufficient credits
  • Large Files: Reduce image size if uploads fail due to size limits
  • Inaccurate Extraction: Try specifying graph type and axis labels manually for better results
  • Origin Detection: The system now correctly uses graph origin instead of image corners

License

This project is open source. Please check the license file for details.

Contributing

Contributions are welcome! Please submit issues and pull requests on the project repository.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published