-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp-1.py
More file actions
61 lines (45 loc) · 1.35 KB
/
app-1.py
File metadata and controls
61 lines (45 loc) · 1.35 KB
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 matplotlib import image
from pathy import BasePath
import tensorflow as tf
import numpy as np
from PIL import Image
import cv2
from keras.models import load_model
from flask import Flask, request, render_template
from werkzeug.utils import secure_filename
app = Flask(__name__)
model=load_model('BrainTumor10Epochs.h5')
print('Model loaded. Check http://127.0.0.1/')
def get_className(classNo):
if classNo==0:
return"No Brain Tumor"
elif classNo==1:
return"Yes Brain Tumor"
def getResult(img):
image=cv2.imread(img)
image = Image.fromarray(image, 'RGB')
image = image.resize((224, 224))
image=np.array(image)
input_img = np.expand_dims(image, axis=0)
result=model.predict_step(input_img)
return result
@app.route('/', methods=['GET'])
def index():
return render_template('index.html')
@app.route('/predict', methods=['GET', 'POST'])
def upload():
if request.method == 'POST':
f = request.files['file']
basepath = os.path.dirname(__file__)
file_path = os.path.join(
basepath, 'uploads', secure_filename(f.filename))
f.save(file_path)
value=getResult(file_path)
result=get_className(value)
return result
return None
#if __name__ == '_main_':
# app.run(debug=True)
if __name__ == '__main__':
app.run(host='0.0.0.0')