-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3f02bb5
commit e7395ab
Showing
4 changed files
with
76 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import requests | ||
from server import FileDescription | ||
|
||
url="http://localhost:8000/upload/" | ||
files = {'aFile': ("ibu-claims-complaint-rules.pdf", open('./ibu-claims-complaint-rules.pdf', 'rb'), "application/pdf")} | ||
|
||
fd= FileDescription(name="claim_complaint_rules", | ||
description="a set of rules to manage complaints", | ||
type="pdf", | ||
file_name="ibu-claims-complaint-rules.pdf") | ||
|
||
response = requests.post(url, params=fd , files=files) | ||
|
||
print(response.text.encode("utf-8")) |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
from fastapi import FastAPI, UploadFile, File, Depends | ||
from pypdf import PdfReader | ||
from pydantic import BaseModel | ||
from typing import Optional | ||
import uvicorn | ||
|
||
app = FastAPI() | ||
class FileDescription(BaseModel): | ||
name: Optional[str] = '' | ||
description: Optional[str] = '' | ||
type: str= "md" | ||
file_name: Optional[str] = '' | ||
|
||
|
||
@app.post("/upload") | ||
async def upload_file(fd: FileDescription = Depends(), aFile: UploadFile = File(...)): | ||
print(fd) | ||
contents = await aFile.read() | ||
f = open("./file.pdf", "wb") | ||
f.write(contents) | ||
f.close() | ||
reader = PdfReader("./file.pdf") | ||
txt = "" | ||
for page in range(len(reader.pages)): | ||
pageObj = reader.pages[page] | ||
txt+= pageObj.extract_text(extraction_mode="layout") | ||
rettxt=txt.encode("utf-8") | ||
return rettxt | ||
|
||
|
||
|
||
if __name__ == "__main__": | ||
uvicorn.run(app, host="0.0.0.0", port=8000) |