Spaces:
Running
Running
Istvan-Adem
commited on
Commit
·
0b19cec
1
Parent(s):
de5b934
add jpeg
Browse files- ocr/api/message/views.py +7 -2
ocr/api/message/views.py
CHANGED
@@ -1,4 +1,4 @@
|
|
1 |
-
from fastapi import File, UploadFile
|
2 |
|
3 |
from ocr.api.message import ocr_router
|
4 |
from ocr.api.message.openai_request import generate_report
|
@@ -13,7 +13,12 @@ async def get_all_chat_messages(
|
|
13 |
) -> OcrResponseWrapper[OcrResponse]:
|
14 |
try:
|
15 |
contents = await file.read()
|
16 |
-
|
|
|
|
|
|
|
|
|
|
|
17 |
text_content = extract_text_from_images(images)
|
18 |
# response = await generate_report(text_content)
|
19 |
return OcrResponseWrapper(data=OcrResponse(text=text_content))
|
|
|
1 |
+
from fastapi import File, UploadFile, HTTPException
|
2 |
|
3 |
from ocr.api.message import ocr_router
|
4 |
from ocr.api.message.openai_request import generate_report
|
|
|
13 |
) -> OcrResponseWrapper[OcrResponse]:
|
14 |
try:
|
15 |
contents = await file.read()
|
16 |
+
if file.filename.endswith('.pdf'):
|
17 |
+
images = divide_images(contents)
|
18 |
+
elif file.filename.endswith(('.jpg', ".jpeg", ".png")):
|
19 |
+
images = [contents]
|
20 |
+
else:
|
21 |
+
raise HTTPException(status_code=400, detail='Unsupported file type.')
|
22 |
text_content = extract_text_from_images(images)
|
23 |
# response = await generate_report(text_content)
|
24 |
return OcrResponseWrapper(data=OcrResponse(text=text_content))
|