This project demonstrates the usage of Azure AI Document Intelligence (formerly Form Recognizer) to analyze and extract information from documents using Python.
- Document layout analysis
- Handwritten text detection
- Text content extraction
- Table analysis
- Selection marks (checkboxes, radio buttons) detection
- Python 3.8 or later
- Azure Document Intelligence resource
- Required packages:
- azure-ai-documentintelligence
- azure-core
- Clone this repository:
git clone https://github.com/lphan3/Doc.int.AI.git
cd Doc.int.AI- Create and activate a virtual environment (recommended):
# Windows
python -m venv venv
.\venv\Scripts\activate
3. Install the required packages:
```bash
# Install all required packages
pip install azure-ai-documentintelligence azure-core
# Verify installation
pip list | findstr azure-
Configure your Azure credentials:
- Go to Azure Portal
- Create or select your Document Intelligence resource
- Copy the endpoint URL and API key
- Update
Starting.pywith your credentials:endpoint = "YOUR_ENDPOINT_HERE" # e.g., "https://your-resource.cognitiveservices.azure.com/" key = "YOUR_KEY_HERE" # Your Azure Document Intelligence API key
-
Test the installation:
python Starting.pyBefore running the code, you need to configure your Azure Document Intelligence credentials:
- Get your endpoint URL and API key from the Azure Portal
- Update the following variables in
Starting.py:endpoint: Your Azure Document Intelligence endpoint URLkey: Your Azure Document Intelligence API key
The sample code demonstrates several features:
-
Document Analysis
- Uses the "prebuilt-layout" model for general document analysis
- Supports URL-based document analysis
- Sample document URL provided for testing
-
Style Analysis
- Detects handwritten content in documents
- Processes document styles
-
Page Content Analysis
- Extracts text lines from each page
- Processes selection marks (checkboxes, radio buttons)
- Handles UTF-8 encoded content
-
Table Analysis
- Extracts table structure
- Processes table cells and their content
- Provides row and column information
The code will output:
- Document style information (handwritten content detection)
- Text content from each line
- Selection mark states and confidence levels
- Table dimensions and cell contents
The code is organized into clear sections:
- Imports and Dependencies
- Azure Configuration
- Sample Document Setup
- Client Initialization
- Document Analysis
- Style Analysis
- Page Content Analysis
- Table Analysis
This is a sample implementation for presentation purposes. For production use, ensure proper error handling and security measures are in place.
For Excel interaction, you can use the following packages:
- Most popular and powerful data manipulation library
- Excellent for Excel file handling and lookup operations
- Installation:
pip install pandas openpyxl - Features:
- Read/write Excel files
- VLOOKUP-like operations using
merge() - Data filtering and transformation
- Large dataset handling
- Direct Excel file manipulation
- Installation:
pip install openpyxl - Features:
- Read/write Excel files
- Cell formatting
- Formula support
- Charts and images
- Excel automation with Python
- Installation:
pip install xlwings - Features:
- Interact with Excel application
- Run Excel macros
- Real-time Excel updates
- Excel formula execution
- Lightweight Excel file handling
- Installation:
pip install xlrd xlwt - Features:
- Read Excel files (xlrd)
- Write Excel files (xlwt)
- Basic Excel operations
For most use cases, we recommend using pandas with openpyxl:
pip install pandas openpyxlExample usage with pandas for lookup operations:
import pandas as pd
# Read Excel files
df1 = pd.read_excel('source.xlsx')
df2 = pd.read_excel('lookup.xlsx')
# Perform VLOOKUP-like operation
result = pd.merge(df1, df2, on='key_column', how='left')