-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclient_example.py
More file actions
32 lines (26 loc) · 1011 Bytes
/
Copy pathclient_example.py
File metadata and controls
32 lines (26 loc) · 1011 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
import requests
import sys
def extract_doc(file_path, api_url="http://127.0.0.1:8000/extract"):
"""
Sends a file to the docling-extractor API and prints the result.
"""
try:
print(f"Sending {file_path} to {api_url}...")
with open(file_path, 'rb') as f:
files = {'file': f}
response = requests.post(api_url, files=files)
if response.status_code == 200:
data = response.json()
print("\n--- Markdown Content (First 1000 chars) ---")
print(data.get("markdown")[:1000] + "...\n")
print("Extraction Successful!")
else:
print(f"Error: {response.status_code} - {response.text}")
except Exception as e:
print(f"Failed to request: {e}")
if __name__ == "__main__":
if len(sys.argv) < 2:
print("Usage: python client_example.py <path_to_document>")
else:
file_path = sys.argv[1]
extract_doc(file_path)