|
try: from pip._internal.operations import freeze |
|
except ImportError: |
|
from pip.operations import freeze |
|
|
|
pkgs = freeze.freeze() |
|
for pkg in pkgs: print(pkg) |
|
|
|
from fastapi import FastAPI, HTTPException, File, UploadFile |
|
from fastapi.middleware.cors import CORSMiddleware |
|
from PyPDF2 import PdfReader |
|
|
|
app = FastAPI() |
|
|
|
app.add_middleware( |
|
CORSMiddleware, |
|
allow_origins=["*"], |
|
allow_credentials=True, |
|
allow_methods=["*"], |
|
allow_headers=["*"], |
|
) |
|
|
|
@app.post("/get_ocr_data/") |
|
async def get_data(pdf: UploadFile = File(...)): |
|
try: |
|
|
|
pdf_reader = PdfReader(pdf.file) |
|
text = "" |
|
|
|
|
|
for page in pdf_reader.pages: |
|
text += page.extract_text() |
|
|
|
|
|
return {"text": text.strip()} |
|
|
|
except Exception as e: |
|
raise HTTPException(status_code=500, detail=f"Error processing PDF: {str(e)}") |
|
|
|
|
|
|