vision-parse

repository·main·Indexed 19 days ago

https://github.com/iamarunbrahma/vision-parse

A tool that uses Vision Language Models (VLMs) to convert PDF documents into formatted markdown. It supports complex content extraction such as LaTeX equations, tables, and images. vision-parse works with cloud APIs including OpenAI, Azure OpenAI, and Google Gemini, as well as local hosting via Ollama.

Tokens
10.7K
Snippets
41
Records
48
Agent score
65%

What's inside vision-parse

  1. Configure and verify Ollama server

    main

    After installation, you need to pull the required vision model and ensure the server is running. Vision Parse requires the llama3.2-vision:11b model.

    1. Pull the model: ollama pull llama3.2-vision:11b
    2. Start the server: ollama serve
    3. Verify the server is responding by checking the version endpoint via curl.
    # Pull the required vision model
    ollama pull llama3.2-vision:11b
    
    # Start the Ollama server
    ollama serve
    
    # Verify server status
    curl http://localhost:11434/api/version
  2. Install vision-parse

    main

    You can install the core package via pip. To include all additional dependencies required for using OpenAI or Gemini models, use the [all] extra.

    Core installation:

    pip install vision-parse

    Full installation (with OpenAI/Gemini dependencies):

    pip install 'vision-parse[all]'

    Install from source:

    pip install 'git+https://github.com/iamarunbrahma/vision-parse.git#egg=vision-parse[all]'
    pip install 'vision-parse[all]'
  3. Run benchmarks for Vision Parse

    main

    You can evaluate the performance of Vision Parse on your own machine using the provided benchmarking script.

    1. Install the required benchmark dependencies:
    pip install --no-cache-dir -r benchmarks/requirements.txt
    1. Run the scoring script (ensure you update the pdf_path and benchmark_results_path within the script or via arguments if supported):
    python benchmarks/scoring.py
    pip install --no-cache-dir -r benchmarks/requirements.txt
    python benchmarks/scoring.py
  4. Build and Run the Vision Parse Docker Container

    main

    Follow these steps to deploy the application:

    1. Enable GPU (Optional): If you have an Nvidia GPU, uncomment the deploy section in your docker-compose.yml to reserve the GPU device.
    2. Build and Start: Use docker compose build to create the image and docker compose up -d to start the container in detached mode.
    3. Verify: Run docker ps to ensure the container is active.
    4. Execute Application: Run the Gradio application inside the container using docker compose exec.
    # 1. (Optional) Edit docker-compose.yml to include:
    # deploy:
    #   resources:
    #     reservations:
    #       devices:
    #         - driver: nvidia
    #           count: 1
    #           capabilities: [gpu]
    
    # 2. Build and start
    docker compose build
    docker compose up -d
    
    # 3. Verify
    docker ps
    
    # 4. Run the application
    docker compose exec vision-parse python docs/examples/gradio_app.py
  5. Install Vision Parse via Docker on Linux

    main

    To set up Vision Parse on Linux, you must install Docker Engine, Docker Compose, and optionally the Nvidia Container Toolkit for GPU support.

    macOS Users: Download and install Docker Desktop, which includes Docker Compose.

    # Install Docker Engine
    curl -fsSL https://get.docker.com -o get-docker.sh
    sudo sh get-docker.sh
    
    # Install Docker Compose
    sudo apt-get install docker-compose
    
    # For GPU Support (Optional)
    curl -fsSL https://nvidia.github.io/libnvidia-container/gpgkey | sudo gpg --dearmor -o /usr/share/keyrings/nvidia-container-toolkit-keyring.gpg
    
    curl -s -L https://nvidia.github.io/libnvidia-container/stable/deb/nvidia-container-toolkit.list | \
      sed 's#deb https://#deb [signed-by=/usr/share/keyrings/nvidia-container-toolkit-keyring.gpg] https://#g' | \
      sudo tee /etc/apt/sources.list.d/nvidia-container-toolkit.list
    
    sudo apt-get update
    sudo apt-get install -y nvidia-container-toolkit
  6. Install Ollama locally

    main

    To use Vision Parse with a local LLM provider, you must first install Ollama on your operating system. Use the following commands based on your platform:

    • Linux: Use the curl install script.
    • MacOS: Use Homebrew.
    • Windows: Download the installer directly from the official website.
    # Linux
    curl -fsSL https://ollama.com/install.sh | sh
    
    # MacOS
    brew install ollama
  7. Configure the OpenAI Client

    main

    To customize OpenAI connections, pass a configuration dictionary to the openai_config parameter during VisionParser initialization.

    Model-specific parameters (like temperature or max_tokens) should be passed as additional keyword arguments (kwargs) to the VisionParser class, not inside the openai_config dictionary.

    # Example usage pattern
    parser = VisionParser(
        openai_config={
            'OPENAI_BASE_URL': 'https://api.openai.com/v1',
            'OPENAI_MAX_RETRIES': 5,
            'OPENAI_TIMEOUT': 120.0
        },
        max_tokens=500  # Model-specific parameter passed as kwarg
    )
  8. Configure the Azure OpenAI Client

    main

    To use Azure OpenAI, pass the required credentials and endpoint information via the openai_config parameter when initializing VisionParser.

    parser = VisionParser(
        openai_config={
            'AZURE_OPENAI_API_KEY': 'your-api-key',
            'AZURE_ENDPOINT_URL': 'https://your-endpoint.azure.com/',
            'AZURE_DEPLOYMENT_NAME': 'your-deployment-name',
            'AZURE_OPENAI_API_VERSION': '2024-08-01-preview'
        }
    )
  9. Configure Environment Variables for Vision Parse

    main

    Before running the container, you must export the necessary environment variables. MODEL_NAME is required and should be selected from the list of supported models. API keys for OpenAI or Gemini are optional but required if using those specific models.

    # Required: Choose one of the following models
    export MODEL_NAME=llama3.2-vision:11b
    
    # Optional: API keys (required only for specific models)
    export OPENAI_API_KEY=your_openai_api_key
    export GEMINI_API_KEY=your_gemini_api_key
  10. Configure the Ollama Client

    main

    When initializing the VisionParser class, you can customize the Ollama connection by passing a configuration dictionary to the ollama_config parameter.

    For model-specific parameters (such as temperature or top_p), pass them directly as additional keyword arguments (kwargs) to the VisionParser constructor rather than inside the ollama_config dictionary.

    # Example usage pattern
    parser = VisionParser(
        ollama_config={
            'OLLAMA_HOST': 'http://your-host:11434',
            'OLLAMA_NUM_PARALLEL': 4,
            'OLLAMA_REQUEST_TIMEOUT': 300.0
        },
        temperature=0.2  # Model-specific parameter passed as kwarg
    )