added consult notes
Browse files- ocr/__init__.py +3 -0
- ocr/api/consult/__init__.py +7 -0
- ocr/api/consult/db_requests.py +0 -0
- ocr/api/consult/dto.py +0 -0
- ocr/api/consult/schemas.py +0 -0
- ocr/api/consult/views.py +8 -0
- ocr/api/utils.py +16 -0
- requirements.txt +14 -0
ocr/__init__.py
CHANGED
@@ -18,6 +18,9 @@ def create_app() -> FastAPI:
|
|
18 |
from ocr.api.message import message_router
|
19 |
app.include_router(message_router, tags=['message'])
|
20 |
|
|
|
|
|
|
|
21 |
app.add_middleware(
|
22 |
CORSMiddleware,
|
23 |
allow_origins=["*"],
|
|
|
18 |
from ocr.api.message import message_router
|
19 |
app.include_router(message_router, tags=['message'])
|
20 |
|
21 |
+
from ocr.api.consult import consult_router
|
22 |
+
app.include_router(consult_router, tags=['consult'])
|
23 |
+
|
24 |
app.add_middleware(
|
25 |
CORSMiddleware,
|
26 |
allow_origins=["*"],
|
ocr/api/consult/__init__.py
ADDED
@@ -0,0 +1,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from fastapi.routing import APIRouter
|
2 |
+
|
3 |
+
consult_router = APIRouter(
|
4 |
+
prefix="/api/consult", tags=["consult"]
|
5 |
+
)
|
6 |
+
|
7 |
+
from . import views
|
ocr/api/consult/db_requests.py
ADDED
File without changes
|
ocr/api/consult/dto.py
ADDED
File without changes
|
ocr/api/consult/schemas.py
ADDED
File without changes
|
ocr/api/consult/views.py
ADDED
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from ocr.api.consult import consult_router
|
2 |
+
from ocr.api.utils import text_to_pdf_base64
|
3 |
+
from ocr.core.wrappers import OcrResponseWrapper
|
4 |
+
|
5 |
+
|
6 |
+
@consult_router.post('/{reportId}/generate')
|
7 |
+
async def generate_consult_report(reportId: str) -> OcrResponseWrapper[str]:
|
8 |
+
return OcrResponseWrapper(data=text_to_pdf_base64('## Vika Kakashka'))
|
ocr/api/utils.py
CHANGED
@@ -2,8 +2,10 @@ import base64
|
|
2 |
import io
|
3 |
import re
|
4 |
|
|
|
5 |
import pytesseract
|
6 |
from PIL import Image
|
|
|
7 |
from pdf2image import convert_from_bytes
|
8 |
|
9 |
|
@@ -63,3 +65,17 @@ def prepare_request_content(images: list[bytes]):
|
|
63 |
]
|
64 |
]
|
65 |
return content
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2 |
import io
|
3 |
import re
|
4 |
|
5 |
+
import markdown2
|
6 |
import pytesseract
|
7 |
from PIL import Image
|
8 |
+
from fpdf import FPDF
|
9 |
from pdf2image import convert_from_bytes
|
10 |
|
11 |
|
|
|
65 |
]
|
66 |
]
|
67 |
return content
|
68 |
+
|
69 |
+
|
70 |
+
def text_to_pdf_base64(text: str) -> str:
|
71 |
+
pdf = FPDF()
|
72 |
+
pdf.set_auto_page_break(auto=True, margin=15)
|
73 |
+
pdf.add_page()
|
74 |
+
pdf.set_font("Arial", size=12)
|
75 |
+
html_text = markdown2.markdown(text)
|
76 |
+
plain_text = ''.join(html_text.split('<')[::2])
|
77 |
+
pdf.multi_cell(0, 10, plain_text)
|
78 |
+
pdf_str = pdf.output(dest="S")
|
79 |
+
pdf_bytes = pdf_str.encode("latin1")
|
80 |
+
pdf_base64 = base64.b64encode(pdf_bytes).decode('utf-8')
|
81 |
+
return pdf_base64
|
requirements.txt
CHANGED
@@ -1,34 +1,48 @@
|
|
1 |
annotated-types==0.7.0
|
2 |
anyio==4.8.0
|
|
|
3 |
certifi==2025.1.31
|
|
|
4 |
click==8.1.8
|
|
|
5 |
distro==1.9.0
|
6 |
dnspython==2.7.0
|
7 |
fastapi==0.115.8
|
|
|
|
|
8 |
h11==0.14.0
|
9 |
httpcore==1.0.7
|
10 |
httptools==0.6.4
|
11 |
httpx==0.28.1
|
12 |
idna==3.10
|
13 |
jiter==0.8.2
|
|
|
14 |
motor==3.7.0
|
15 |
openai==1.59.9
|
16 |
packaging==24.2
|
17 |
pdf2image==1.17.0
|
|
|
18 |
pillow==11.1.0
|
|
|
19 |
pydantic==2.10.6
|
20 |
pydantic_core==2.27.2
|
21 |
pydash==8.0.5
|
|
|
22 |
pymongo==4.11
|
|
|
23 |
pytesseract==0.3.13
|
24 |
python-dotenv==1.0.1
|
25 |
python-multipart==0.0.20
|
26 |
PyYAML==6.0.2
|
27 |
sniffio==1.3.1
|
28 |
starlette==0.45.3
|
|
|
|
|
29 |
tqdm==4.67.1
|
30 |
typing_extensions==4.12.2
|
31 |
uvicorn==0.34.0
|
32 |
uvloop==0.21.0
|
33 |
watchfiles==1.0.4
|
|
|
34 |
websockets==14.2
|
|
|
|
1 |
annotated-types==0.7.0
|
2 |
anyio==4.8.0
|
3 |
+
Brotli==1.1.0
|
4 |
certifi==2025.1.31
|
5 |
+
cffi==1.17.1
|
6 |
click==8.1.8
|
7 |
+
cssselect2==0.7.0
|
8 |
distro==1.9.0
|
9 |
dnspython==2.7.0
|
10 |
fastapi==0.115.8
|
11 |
+
fonttools==4.56.0
|
12 |
+
fpdf==1.7.2
|
13 |
h11==0.14.0
|
14 |
httpcore==1.0.7
|
15 |
httptools==0.6.4
|
16 |
httpx==0.28.1
|
17 |
idna==3.10
|
18 |
jiter==0.8.2
|
19 |
+
markdown2==2.5.3
|
20 |
motor==3.7.0
|
21 |
openai==1.59.9
|
22 |
packaging==24.2
|
23 |
pdf2image==1.17.0
|
24 |
+
pdfkit==1.0.0
|
25 |
pillow==11.1.0
|
26 |
+
pycparser==2.22
|
27 |
pydantic==2.10.6
|
28 |
pydantic_core==2.27.2
|
29 |
pydash==8.0.5
|
30 |
+
pydyf==0.11.0
|
31 |
pymongo==4.11
|
32 |
+
pyphen==0.17.2
|
33 |
pytesseract==0.3.13
|
34 |
python-dotenv==1.0.1
|
35 |
python-multipart==0.0.20
|
36 |
PyYAML==6.0.2
|
37 |
sniffio==1.3.1
|
38 |
starlette==0.45.3
|
39 |
+
tinycss2==1.4.0
|
40 |
+
tinyhtml5==2.0.0
|
41 |
tqdm==4.67.1
|
42 |
typing_extensions==4.12.2
|
43 |
uvicorn==0.34.0
|
44 |
uvloop==0.21.0
|
45 |
watchfiles==1.0.4
|
46 |
+
webencodings==0.5.1
|
47 |
websockets==14.2
|
48 |
+
zopfli==0.2.3.post1
|