from fastapi import FastAPI, File, UploadFile from fastapi.responses import JSONResponse import uvicorn from parsers import FileParserFactory app = FastAPI() @app.post("/upload") async def upload_file(file: UploadFile = File(...)): try: contents = await file.read() parser = FileParserFactory(use_ocr=False) parser = parser.get_parser(file.filename) content = await parser.parse(contents, file.filename) return JSONResponse( content={"filename": file.filename, "content": content} ) except Exception as e: return JSONResponse(content={"error": str(e)}, status_code=400) if __name__ == "__main__": uvicorn.run(app, host="0.0.0.0", port=8080)