An AI agent that uses Azure Content Understanding to scan and analyze documents, extracting text, tables, and structured data.
Live demo: Open Azure AI Foundry Document Analyzer
pip install -r requirements.txt
Edit config.py and update the following values:
# Azure AI Foundry endpoint - found in your project overview
AZURE_AI_FOUNDRY_ENDPOINT = "https://YOUR_RESOURCE.services.ai.azure.com/api/projects/YOUR_PROJECT"
# Content Understanding endpoint
AZURE_CONTENT_UNDERSTANDING_ENDPOINT = "https://YOUR_RESOURCE.cognitiveservices.azure.com"
# Your API key - found under "Keys and Endpoint" in Azure portal
AZURE_API_KEY = "YOUR_API_KEY_HERE"
# Your deployed model name
MODEL_DEPLOYMENT_NAME = "gpt-4o"
Run the main script for an interactive experience:
python main.py
Available commands:
upload <file_path> - Upload a document for the agent to analyzeanalyze <file_path> - Directly analyze a document (without agent)chat - Start an interactive chat with the agenthelp - Show available commandsquit - Exit the applicationfrom agent import create_document_analyzer_agent
# Create the agent
agent = create_document_analyzer_agent()
# Upload a document
agent.upload_file("/path/to/document.pdf")
# Chat with the agent
response = agent.chat("Please analyze the uploaded document and summarize its contents")
print(response)
# Ask follow-up questions
response = agent.chat("What tables are in the document?")
print(response)
# Clean up when done
agent.cleanup()
from content_understanding import ContentUnderstandingClient
client = ContentUnderstandingClient()
# Extract text from a document
text = client.extract_text("/path/to/document.pdf")
print(text)
# Extract tables
tables = client.extract_tables("/path/to/document.pdf")
for table in tables:
print(f"Table: {table['rowCount']} rows x {table['columnCount']} columns")
# Analyze with custom field schema
fields = {
"invoice_number": {"type": "string", "method": "extract"},
"total_amount": {"type": "number", "method": "extract"},
"vendor_name": {"type": "string", "method": "extract"}
}
result = client.analyze_with_custom_schema(
file_path="/path/to/invoice.pdf",
fields=fields
)
azure-ai-foundry-agent/
├── config.py # Configuration and credentials
├── content_understanding.py # Content Understanding API client
├── agent.py # AI Foundry Agent implementation
├── main.py # Interactive CLI application
├── requirements.txt # Python dependencies
└── README.md # This file
Make sure you’ve updated all placeholder values in config.py with your actual Azure credentials.