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)