gruhit-patel commited on
Commit
2ab4a36
·
verified ·
1 Parent(s): b3aca8d

Update backend.py

Browse files
Files changed (1) hide show
  1. backend.py +43 -42
backend.py CHANGED
@@ -1,43 +1,44 @@
1
- import os
2
- os.environ['TF_CPP_MIN_LOG_LEVEL'] = '3'
3
-
4
- import tensorflow as tf
5
- from fastapi import FastAPI, UploadFile, File
6
- from utils import load_image, preprocess_image, predict
7
- from model import get_model
8
- import json
9
-
10
- app = FastAPI()
11
-
12
- MODEL_WEIGHT_PATH = './finetune_v1_weights.keras'
13
- model = get_model(MODEL_WEIGHT_PATH)
14
-
15
- @app.get("/")
16
- def tester():
17
- return {
18
- "status": "Hello World"
19
- }
20
-
21
- @app.post("/get_prediction")
22
- async def get_prediction(x_ray_image: UploadFile = File(...)):
23
-
24
- # Load the image i.e. convert from bytes -> Image (unit8)
25
- image = load_image(await x_ray_image.read())
26
-
27
- # Preprocess image to make it compatible for model
28
- image = preprocess_image(image)
29
-
30
- # Retrive model prediction
31
- prediction = predict(image, model)
32
-
33
- print("Model Predicted: \n", prediction)
34
-
35
- return {
36
- 'prediction': json.dumps(prediction)
37
- }
38
-
39
- @app.post("/test")
40
- def test():
41
- return {
42
- "status": 10
 
43
  }
 
1
+ import os
2
+ os.environ['TF_CPP_MIN_LOG_LEVEL'] = '3'
3
+
4
+ import tensorflow as tf
5
+ from fastapi import FastAPI, UploadFile, File
6
+ from utils import load_image, preprocess_image, predict
7
+ from model import get_model
8
+ import json
9
+
10
+ app = FastAPI()
11
+
12
+ MODEL_WEIGHT_PATH = './finetune_v1_weights.keras'
13
+ model = get_model(MODEL_WEIGHT_PATH)
14
+ print("Model Loaded Successfully")
15
+
16
+ @app.get("/")
17
+ def tester():
18
+ return {
19
+ "status": "Hello World"
20
+ }
21
+
22
+ @app.post("/get_prediction")
23
+ async def get_prediction(x_ray_image: UploadFile = File(...)):
24
+
25
+ # Load the image i.e. convert from bytes -> Image (unit8)
26
+ image = load_image(await x_ray_image.read())
27
+
28
+ # Preprocess image to make it compatible for model
29
+ image = preprocess_image(image)
30
+
31
+ # Retrive model prediction
32
+ prediction = predict(image, model)
33
+
34
+ print("Model Predicted: \n", prediction)
35
+
36
+ return {
37
+ 'prediction': json.dumps(prediction)
38
+ }
39
+
40
+ @app.post("/test")
41
+ def test():
42
+ return {
43
+ "status": 10
44
  }