-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
61 lines (51 loc) · 1.59 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
import os
from fastapi import FastAPI, Form, File, UploadFile
from pydantic import BaseModel
from fastapi.middleware.cors import CORSMiddleware
from diagnosis import diagnosis
app = FastAPI()
origins = [
'*'
]
app.add_middleware(
CORSMiddleware,
allow_origins=origins,
allow_credentials=True,
allow_methods=["*"],
allow_headers=["*"],
)
class Msg(BaseModel):
msg: str
file: UploadFile
# @app.get("/dataset1")
# async def root():
# diag = diagnosis('cobapng.png')
# return {"message": diag}
@app.post("/pneumonia")
async def create_upload_file(file: UploadFile = File(...)):
try:
contents = file.file.read()
with open(file.filename, 'wb') as f:
f.write(contents)
except Exception:
return {"message": "There was an error uploading the file"}
finally:
file.file.close()
diag = diagnosis(file.filename, 'pneumonia')
if os.path.exists(file.filename):
os.remove(file.filename)
return {"message": f"Successfully uploaded {file.filename}", "diagnosis": diag}
@app.post("/tbc")
async def create_upload_file(file: UploadFile = File(...)):
try:
contents = file.file.read()
with open(file.filename, 'wb') as f:
f.write(contents)
except Exception:
return {"message": "There was an error uploading the file"}
finally:
file.file.close()
diag = diagnosis(file.filename, 'tbc')
if os.path.exists(file.filename):
os.remove(file.filename)
return {"message": f"Successfully uploaded {file.filename}", "diagnosis": diag}