Upload a File (PDF, images)

1import requests
2from typing import List, Dict, Any
3
4def extract_data(api_key: str, file_paths: List[str], prompt: str) -> Dict[str, Any]:
5 url = "https://api2.boundaryml.com/v3/extract"
6 headers = {
7 "Authorization": f"Bearer {api_key}"
8 }
9 files = [('files', open(file_path, 'rb')) for file_path in file_paths]
10 data = {
11 'prompt': prompt
12 }
13 response = requests.post(url, headers=headers, files=files, data=data)
14 response.raise_for_status()
15 return response.json()
16
17# Usage example
18api_key = 'your_api_key_here'
19file_paths = ['path/to/file1.pdf', 'path/to/file2.png']
20prompt = 'Please extract the text content.'
21
22result = extract_data(api_key, file_paths, prompt)
23print(result)