Hey guys, I’m trying to achieve streaming executio...
# daft-dev
n
Hey guys, I’m trying to achieve streaming execution for pdf processing. My use case: 1 pdf that has N pages Each page needs to be run through OCR model (inference endpoint) and entity extraction model (inference endpoint ). Pages have no connection to each other whatsoever. So if page 2 ocr completes before page 1, page 2 entity extraction should start automatically. So I’m looking for a streaming implementation. Does anyone have an already implemented solution? Would help if someone can give me some direction on how to achieve this with DAFT. I am aware that there is a document processing example in the docs but not sure if it is a streaming execution implementation.
Hey… just following back… any chance this is possible with daft? Any help is much appreciated.
c
Sorry for late reply! First, could you help me understand whats the input, is it raw pdf files or do you already have the individual pdf pages available? As for the implementation, assuming you have pages already, i would do something like this. Implement OCR model inference and entity extraction inference as 2 separate UDFs. Then i would use
df.into_batches(1)
to set batch sizes to 1 to get the page by page streaming that you want. You would have code something like this:
Copy code
df = df.into_batches(1)
df = df.with_column("ocr_result", ocr_udf(df["page"]))
df = df.with_column("entities", entity_extract_udf(df["ocr_result"]))
n
It’s raw PDF binary that I’m fetching from a redis key (for now we can assume only 1 PDF). I have to extract pdf pages. I’m using PyMuPDF to extract pages and convert each page to image using a Generator UDF using
daft.func
since each pdf will output into multiple pages. And then maybe the code sample that you pasted @Colin Ho? Is my approach correct?
c
yup! that sounds good to me
n
Cool, Will give it a shot! Also, out of curiosity, does using a DAFT custom I/O
DataSource
help in any way? Or is that an overkill for this use case?
c
probably not, i'm guessing you're using a udf to do the fetch from redis?
n
I’m not using any UDF at the moment to fetch from redis since I’m fetching only one 1 pdf binary at the moment. Will moving that code to UDF benefit me?
c
If it’s only 1 then no
n
Got it, thanks for the help!