Document Processing with AI

This guide demonstrates how to extract content from documents and process it with Taam Cloud’s AI models.

Step 1: Upload and Extract Document Content

First, upload your document to extract its content:

curl -X POST \
  'https://uploud.taam.cloud/upload' \
  -F 'file=@/path/to/document.pdf'

The API will return the extracted content:

{
  "status": true,
  "content": "Document content extracted...",
  "type": "pdf",
  "error": ""
}

Step 2: Process with AI Models

Use the extracted content with Taam Cloud’s AI models:

import os
import requests

# Step 1: Upload and extract document
upload_url = 'https://uploud.taam.cloud/upload'
file_path = '/path/to/document.pdf'

with open(file_path, 'rb') as file:
    files = {'file': file}
    upload_response = requests.post(upload_url, files=files)

document_content = upload_response.json()['content']

# Step 2: Process with AI
ai_url = 'https://api.taam.cloud/v1/chat/completions'
headers = {
    'Authorization': f'Bearer {os.environ.get("TAAM_API_KEY")}',
    'Content-Type': 'application/json'
}

ai_payload = {
    'model': 'gpt-4o',
    'messages': [
        {'role': 'system', 'content': 'You are a document analysis assistant.'},
        {'role': 'user', 'content': f'Summarize this document: {document_content}'}
    ]
}

ai_response = requests.post(ai_url, json=ai_payload, headers=headers)
summary = ai_response.json()['choices'][0]['message']['content']
print(summary)

Working with Large Documents

For large documents, use the embeddings extraction mode:

curl -X POST \
  'https://uploud.taam.cloud/upload' \
  -F 'file=@/path/to/large_document.pdf' \
  -F 'extract_mode=embeddings'

This returns the document split into chunks:

{
  "id": "scrape-aec35e29-703d-4eaf-b1c4-5cda9fd66951",
  "object": "chunks",
  "data": {
    "success": true,
    "data": {
      "chunks": [
        {
          "content": "Chapter 1: Introduction...",
          "total_tokens": 150,
          "from_page": 1
        },
        // Additional chunks...
      ]
    }
  }
}

Process the chunks sequentially or use a RAG pattern:

# Process chunks with AI
chunks = response.json()['data']['data']['chunks']
summaries = []

for idx, chunk in enumerate(chunks):
    ai_payload = {
        'model': 'gpt-4o',
        'messages': [
            {'role': 'system', 'content': 'Summarize the following document section.'},
            {'role': 'user', 'content': chunk['content']}
        ]
    }
    
    chunk_summary = requests.post(ai_url, json=ai_payload, headers=headers)
    summaries.append(f"Section {idx+1}: " + chunk_summary.json()['choices'][0]['message']['content'])

# Combine summaries
final_summary = "\n\n".join(summaries)

Using Document Processing Options

Extract Images from Document

curl -X POST \
  'https://uploud.taam.cloud/upload' \
  -F 'file=@/path/to/document.pdf' \
  -F 'images_only=true'

OCR Processing for Scanned Documents

curl -X POST \
  'https://uploud.taam.cloud/upload' \
  -F 'file=@/path/to/scanned_document.pdf' \
  -F 'enable_ocr=true'

Page-Based Processing

curl -X POST \
  'https://uploud.taam.cloud/upload' \
  -F 'file=@/path/to/document.pdf' \
  -F 'page_based=true'

Best Practices

File Size

For files approaching the size limit (50MB), compress them before uploading

Image Quality

For OCR, ensure images are at least 300 DPI for optimal text extraction

Chunking

Use embeddings mode for large documents to get proper chunking

Headers & Footers

Use remove_headers=true to clean repeated elements from each page

Handling Specific Document Types

PDFs with Forms

curl -X POST \
  'https://uploud.taam.cloud/upload' \
  -F 'file=@/path/to/form.pdf'

The API will extract form fields and their values.

Presentations

curl -X POST \
  'https://uploud.taam.cloud/upload' \
  -F 'file=@/path/to/slides.pptx'

The API preserves slide structure in the extracted content.

Audio Files (Transcription)

curl -X POST \
  'https://uploud.taam.cloud/upload' \
  -F 'file=@/path/to/recording.mp3'

Returns the transcribed text from the audio file.