app.py 726 Bytes
Newer Older
kihoon.lee's avatar
upload  
kihoon.lee committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
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)