quickpdf-ocr / test_client.py
zasprince8's picture
Upload 5 files
e80e19f verified
raw
history blame contribute delete
924 Bytes
import requests
import sys
def test_ocr(file_path):
url = "http://localhost:8000/ocr"
try:
with open(file_path, "rb") as f:
files = {"file": f}
print(f"Sending {file_path} to {url}...")
response = requests.post(url, files=files)
if response.status_code == 200:
print("Success!")
data = response.json()
print("Text Preview:", data["text"][:200], "...")
print(f"Total Pages: {len(data['pages'])}")
else:
print(f"Error {response.status_code}: {response.text}")
except FileNotFoundError:
print(f"File not found: {file_path}")
except Exception as e:
print(f"Request failed: {e}")
if __name__ == "__main__":
if len(sys.argv) < 2:
print("Usage: python test_client.py <path_to_file>")
else:
test_ocr(sys.argv[1])