Untitled
unknown
python
a year ago
775 B
12
Indexable
from fastapi import FastAPI, File, UploadFile
from PyPDF2 import PdfReader
import uvicorn
import aiofiles
import os
app = FastAPI()
@app.post("/upload-file")
async def index(file: UploadFile = File(...)):
print(file.file)
local_file_path = 'Data/' + file.filename
async with aiofiles.open(local_file_path, 'wb') as f_obj:
content = await file.read()
await f_obj.write(content)
reader = PdfReader(local_file_path)
number_of_pages = len(reader.pages)
page = reader.pages[0]
text = page.extract_text()
os.remove(local_file_path)
return {"Hello": "World"}
if __name__ == "__main__":
directories = os.listdir()
if 'Data' not in directories:
os.mkdir("Data")
uvicorn.run(app, host='0.0.0.0', port=8000)
Editor is loading...
Leave a Comment