-
Notifications
You must be signed in to change notification settings - Fork 0
/
code_py.py
54 lines (45 loc) · 1.46 KB
/
code_py.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
from flask import Flask, render_template, request
from werkzeug.utils import secure_filename
#from keras.preprocessing.image import ImageDataGenerator
import tensorflow as tf
import numpy as np
import os
from PIL import Image
import shutil
upload_folder = 'uploaded/image'
if os.path.exists(upload_folder):
shutil.rmtree(upload_folder)
os.makedirs(upload_folder)
model = tf.keras.models.load_model('Brain tumor classification.h5')
app = Flask(__name__)
app.config['UPLOAD_FOLDER'] = upload_folder
@app.route('/')
def upload_f():
return render_template('CNN_deploy.html')
def finds(file_path):
#img_path = "uploaded"
image = Image.open(file_path)
image = image.resize((150,150))
image = np.array(image)
image = np.expand_dims(image, axis=0)
predi = model.predict(image)
predic = np.argmax(predi)
if predic==0:
pred = "No tumor"
elif predic==1:
pred = "Pituitary tumor"
elif predic==2:
pred = "Meningioma tumor"
elif predic==3:
pred = "Glioma tumor"
return str(pred)
@app.route('/uploader', methods = ['GET', 'POST'])
def upload_file():
if request.method == 'POST':
f = request.files['file']
file_path = os.path.join(app.config['UPLOAD_FOLDER'], secure_filename(f.filename))
f.save(file_path)
val = finds(file_path)
return render_template('pred.html', ss = val)
if __name__ == '__main__':
app.run(debug=True)