Spaces:
Sleeping
Sleeping
Download test_client.py from vamsi1103/flask-ocr-api: direct link, hf CLI and curl.
- Browser
- Download file 1.36 kB
-
https://huggingface.co/spaces/vamsi1103/flask-ocr-api/resolve/main/test_client.py
- Command line
-
hf download hf://spaces/vamsi1103/flask-ocr-api/test_client.py
-
curl -L -o test_client.py https://huggingface.co/spaces/vamsi1103/flask-ocr-api/resolve/main/test_client.py
1.36 kB
| import requests | |
| import sys | |
| import json | |
| import io | |
| sys.stdout = io.TextIOWrapper(sys.stdout.buffer, encoding='utf-8') | |
| def test_ocr(image_path): | |
| url = "https://vamsi1103-flask-ocr-api.hf.space/ocr" | |
| print(f"Testing OCR API with image: {image_path}") | |
| try: | |
| with open(image_path, "rb") as file: | |
| response = requests.post(url, files={"file": file}, timeout=60) | |
| if response.status_code == 200: | |
| data = response.json() | |
| with open("hf_api_response.json", "w", encoding="utf-8") as f: | |
| json.dump(data, f, ensure_ascii=False, indent=2) | |
| print("Successfully received API Response! Saved to hf_api_response.json") | |
| print(f"Date: {data.get('date')}") | |
| print(f"Total items returned: {len(data.get('items', []))}") | |
| for i, it in enumerate(data.get('items', [])[:15]): | |
| print(f" {i+1}. {it.get('name')} -> {it.get('rate') or it.get('available_rates')} (text: {it.get('rate_text')})") | |
| else: | |
| print(f"Error {response.status_code}: {response.text}") | |
| except Exception as e: | |
| print(f"Failed to connect or process response: {e}") | |
| if __name__ == "__main__": | |
| if len(sys.argv) > 1: | |
| test_ocr(sys.argv[1]) | |
| else: | |
| print("Usage: python test_client.py <path_to_image>") | |