UdasriHasindu commited on
Commit
645e4b2
·
1 Parent(s): fe2c376

create post routes to classify drawings

Browse files
Files changed (1) hide show
  1. main.py +32 -2
main.py CHANGED
@@ -1,4 +1,4 @@
1
- from fastapi import FastAPI
2
  from services import predictor
3
  from contextlib import asynccontextmanager
4
 
@@ -37,4 +37,34 @@ async def root():
37
  return {
38
  "status": "ok",
39
  "message": "Welcome to the Motor Impairment Score API"
40
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from fastapi import FastAPI, UploadFile, File, HTTPException
2
  from services import predictor
3
  from contextlib import asynccontextmanager
4
 
 
37
  return {
38
  "status": "ok",
39
  "message": "Welcome to the Motor Impairment Score API"
40
+ }
41
+
42
+
43
+
44
+ @app.post("/predict/wave")
45
+ async def predict_wave_endpoint(file: UploadFile = File(...)):
46
+
47
+ if not file.content_type.startswith("image/"):
48
+ raise HTTPException(status_code=400, detail="Invalid file type. Please upload an image.")
49
+
50
+ try:
51
+ image_bytes = await file.read()
52
+ result = predictor.predict_wave(image_bytes)
53
+ return result
54
+ except Exception as e:
55
+ raise HTTPException(status_code=500, detail=str(e))
56
+
57
+
58
+
59
+ @app.post("/predict/spiral")
60
+ async def predict_spiral_endpoint(file: UploadFile = File(...)):
61
+
62
+ if not file.content_type.startswith("image/"):
63
+ raise HTTPException(status_code=400, detail="Invalid file type. Please upload an image.")
64
+
65
+ try:
66
+ image_bytes = await file.read()
67
+ result = predictor.predict_spiral(image_bytes)
68
+ return result
69
+ except Exception as e:
70
+ raise HTTPException(status_code=500, detail=str(e))