File size: 729 Bytes
66bfcea
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
from fastapi import FastAPI, UploadFile, File
from pypdf import PdfReader
from io import BytesIO
import uvicorn

app = FastAPI()

@app.post("/extract-text")
async def extract_text(file: UploadFile = File(...)):
    try:
        print(f"📄 Parsing: {file.filename}")
        content = await file.read()
        pdf_reader = PdfReader(BytesIO(content))

        text = ""
        for page in pdf_reader.pages:
            text += page.extract_text() + "\n"

        return {"status": "success", "text": text}
    except Exception as e:
        print(f"❌ Error: {str(e)}")
        return {"status": "error", "error": str(e)}

if __name__ == "__main__":
    uvicorn.run(app, host="127.0.0.1", port=8000)