Views
No views yet
app.py: Local testing application for the endpointhandler.py: The main handler that processes OCR requestsapp_gradio.py: The original Gradio-based demo application (kept for reference)HF_ENDPOINT.md: Detailed documentation for using the endpointch)en)fr)german)korean)japan)python app.py --img_path ./example_imgs/example.jpg --lang en --confidence 0.5 --return_image Truetest_result.jsontest_result.jpg (if return_image is True)HF_ENDPOINT.md for detailed instructions on deploying and using this as a Hugging Face Inference Endpoint.1import requests
2import base64
3from PIL import Image
4import io
5
6# Load image
7image = Image.open("example.jpg")
8buffered = io.BytesIO()
9image.save(buffered, format="JPEG")
10encoded_image = base64.b64encode(buffered.getvalue()).decode('utf-8')
11
12# API endpoint (when deployed to Hugging Face)
13API_URL = "https://your-endpoint-url.huggingface.cloud"
14headers = {
15 "Authorization": f"Bearer {API_TOKEN}",
16 "Content-Type": "application/json"
17}
18
19# Request data
20data = {
21 "inputs": encoded_image,
22 "parameters": {
23 "lang": "en",
24 "confidence": 0.5,
25 "return_image": False
26 }
27}
28
29# Send request
30response = requests.post(API_URL, headers=headers, json=data)
31result = response.json()
32
33# Process results
34for item in result["result"]:
35 print(f"Text: {item['text']}, Confidence: {item['score']}")python app_gradio.py