Spaces:
Sleeping
Sleeping
Download test_uploaded_image.py from vamsi1103/flask-ocr-api: direct link, hf CLI and curl.
- Browser
- Download file 1.73 kB
-
https://huggingface.co/spaces/vamsi1103/flask-ocr-api/resolve/main/test_uploaded_image.py
- Command line
-
hf download hf://spaces/vamsi1103/flask-ocr-api/test_uploaded_image.py
-
curl -L -o test_uploaded_image.py https://huggingface.co/spaces/vamsi1103/flask-ocr-api/resolve/main/test_uploaded_image.py
1.73 kB
| import sys | |
| import io | |
| import json | |
| from PIL import Image | |
| import numpy as np | |
| from rapidocr_onnxruntime import RapidOCR | |
| from app.preprocess import preprocess_image | |
| from app.parser import parse_ocr_results | |
| sys.stdout = io.TextIOWrapper(sys.stdout.buffer, encoding='utf-8') | |
| img_path = r"C:\Users\USER\.gemini\antigravity-ide\brain\695a8dea-df49-472d-925c-a43945b4677b\.user_uploaded\media_1791360104161.jpg" | |
| img = Image.open(img_path).convert("RGB") | |
| img_np = np.array(img) | |
| processed = preprocess_image(img_np) | |
| print("--- 1. Testing Default RapidOCR Engine ---") | |
| default_engine = RapidOCR() | |
| res_default, _ = default_engine(processed) | |
| print(f"Default engine detected {len(res_default) if res_default else 0} fragments.") | |
| for item in (res_default or [])[:10]: | |
| print(f" {item[1]} (conf: {float(item[2]):.2f})") | |
| print("\n--- 2. Testing Telugu Model RapidOCR Engine ---") | |
| telugu_engine = RapidOCR(rec_model_path='models/telugu/rec.onnx', rec_keys_path='models/telugu/dict.txt') | |
| res_telugu, _ = telugu_engine(processed) | |
| print(f"Telugu engine detected {len(res_telugu) if res_telugu else 0} fragments.") | |
| for item in (res_telugu or [])[:20]: | |
| print(f" {item[1]} (conf: {float(item[2]):.2f})") | |
| # Let's save both raw outputs for detailed analysis | |
| with open("test_raw_comparison.json", "w", encoding="utf-8") as f: | |
| json.dump({ | |
| "default": [{"text": str(i[1]), "conf": float(i[2]), "box": i[0].tolist() if hasattr(i[0], "tolist") else i[0]} for i in (res_default or [])], | |
| "telugu": [{"text": str(i[1]), "conf": float(i[2]), "box": i[0].tolist() if hasattr(i[0], "tolist") else i[0]} for i in (res_telugu or [])] | |
| }, f, ensure_ascii=False, indent=2) | |
| print("\nSaved raw comparison to test_raw_comparison.json") | |