Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion ocr.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ async def read_images_from_dir(dir_path, lang='eng', write_to_file=False):
converted_text[os.path.join(dir_path, file_)] = text
if write_to_file:
for file_path, text in converted_text.items():
_write_to_file(text, os.path.splitext(file_path)[0] + ".txt")
_write_to_file(text, f'{os.path.splitext(file_path)[0]}.txt')
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function read_images_from_dir refactored with the following changes:

return converted_text

def _write_to_file(text, file_path):
Expand Down
10 changes: 6 additions & 4 deletions server.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,12 @@ async def bulk_extract_text(request: Request, bg_task: BackgroundTasks):

@app.get("/api/v1/bulk_output/{task_id}")
async def bulk_output(task_id):
text_map = {}
for file_ in os.listdir(task_id):
if file_.endswith("txt"):
text_map[file_] = open(os.path.join(task_id, file_)).read()
text_map = {
file_: open(os.path.join(task_id, file_)).read()
for file_ in os.listdir(task_id)
if file_.endswith("txt")
}

Comment on lines -36 to +41
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function bulk_output refactored with the following changes:

return {"task_id": task_id, "output": text_map}

def _save_file_to_disk(uploaded_file, path=".", save_as="default"):
Expand Down