abhi264 commited on
Commit
1e32159
1 Parent(s): 30c6048

Upload 4 files

Browse files
Files changed (4) hide show
  1. Dockerfile +11 -0
  2. app.py +44 -0
  3. requirements.txt +6 -0
  4. vgg19_model.h5 +3 -0
Dockerfile ADDED
@@ -0,0 +1,11 @@
 
 
 
 
 
 
 
 
 
 
 
 
1
+ FROM python:3.9.13
2
+
3
+ WORKDIR /code
4
+
5
+ COPY ./requirements.txt /code/requirements.txt
6
+
7
+ RUN pip install --no-cache-dir --upgrade -r /code/requirements.txt
8
+
9
+ COPY . .
10
+
11
+ CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860"]
app.py ADDED
@@ -0,0 +1,44 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from fastapi import FastAPI, UploadFile, File
2
+ from fastapi.middleware.cors import CORSMiddleware
3
+ import numpy as np
4
+ from keras.models import load_model
5
+ from keras.utils import load_img, img_to_array
6
+ from io import BytesIO
7
+ from keras.applications.resnet import preprocess_input
8
+
9
+
10
+ app = FastAPI()
11
+ origins = ["*"]
12
+ app.add_middleware(
13
+ CORSMiddleware,
14
+ allow_origins=origins,
15
+ allow_credentials=True,
16
+ allow_methods=["*"],
17
+ allow_headers=["*"],
18
+ )
19
+ model = load_model('./vgg19_model.h5')
20
+ class_names = ['glioma', 'meningioma', 'no tumor', 'pituitary']
21
+ @app.get('/')
22
+ def welcome():
23
+ return {
24
+ 'success': True,
25
+ 'message': 'server of "brain tumor classification using 4 classes" is up and running successfully.'
26
+ }
27
+ @app.post('/predict')
28
+ async def predict_disease(fileUploadedByUser: UploadFile = File(...)):
29
+
30
+ contents = await fileUploadedByUser.read()
31
+ imageOfUser = load_img(BytesIO(contents), target_size=(224, 224, 3))
32
+ image_to_arr = img_to_array(imageOfUser)
33
+ image_to_arr_preprocess_input = preprocess_input(image_to_arr)
34
+ image_to_arr_preprocess_input_expand_dims = np.expand_dims(image_to_arr_preprocess_input, axis=0)
35
+ prediction = model.predict(image_to_arr_preprocess_input_expand_dims)[0]
36
+ prediction_argmax = np.argmax(prediction)
37
+ prediction_final_result = class_names[prediction_argmax]
38
+ confidence = np.max(prediction) * 100
39
+ return {
40
+ 'success': True,
41
+ 'predicted_result': prediction_final_result,
42
+ 'confidence': f'{confidence:.2f}%',
43
+ 'message': f'Status of the Brain Image: {prediction_final_result} with a confidence of {confidence:.2f}%'
44
+ }
requirements.txt ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
 
1
+ fastapi==0.110.1
2
+ numpy==1.26.4
3
+ uvicorn==0.29.0
4
+ tensorflow==2.10.0
5
+ python-multipart==0.0.9
6
+ Pillow==10.3.0
vgg19_model.h5 ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:aeef7aafeebb64bac69e9a3e509fd7573d034f8f1b3f18ace5bcf355d0227f96
3
+ size 119606704