File size: 924 Bytes
e80e19f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
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])