Skip to content

Commit

Permalink
chore: update code to support process container integration
Browse files Browse the repository at this point in the history
  • Loading branch information
c0deplayer committed Oct 29, 2024
1 parent 466e688 commit 2bd47c4
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions src/documentclassification/ocr/ocr.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

import easyocr
import numpy as np
import requests
from PIL import Image
from fastapi import FastAPI, UploadFile, HTTPException, status
from pdf2image import convert_from_bytes
Expand Down Expand Up @@ -124,7 +125,7 @@ def create_bounding_box(bbox_data: list[tuple[float, float]]) -> list[int]:
@app.post("/ocr")
async def read_text_from_file(
file: UploadFile,
) -> dict[str, list[dict[str, list[int] | str] | bytes]]:
) -> None: # dict[str, list[dict[str, list[int] | str] | bytes]]
logger.info("Received file for OCR: %s", file.filename)

validate_file(file)
Expand All @@ -135,7 +136,10 @@ async def read_text_from_file(

img_bytes = convert_images_to_bytes(images)

return {
"ocr_result": ocr_result,
"images": [base64.b64encode(img) for img in img_bytes],
}
requests.post(
"http://processor:9090/process",
json={
"ocr_result": ocr_result,
"images": [base64.b64encode(img).decode("utf-8") for img in img_bytes],
},
)

0 comments on commit 2bd47c4

Please sign in to comment.