asmaa1 commited on
Commit
d466b88
1 Parent(s): 01785c8

Upload 6 files

Browse files
app.py ADDED
@@ -0,0 +1,49 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from flask import Flask, render_template, request
2
+ import tensorflow as tf
3
+ import numpy as np
4
+ from keras.models import load_model
5
+ from tensorflow.keras.preprocessing.image import load_img, img_to_array
6
+ from io import BytesIO
7
+ import base64
8
+
9
+ app = Flask(__name__)
10
+
11
+ # Load the model
12
+ incept_model = load_model('best_model_2.h5')
13
+ IMAGE_SHAPE = (224, 224)
14
+ classes = ['benign', 'malignant', 'normal']
15
+
16
+ # Function to prepare the image
17
+ def prepare_image(file):
18
+ img = load_img(BytesIO(file.read()), target_size=IMAGE_SHAPE)
19
+ img_array = img_to_array(img)
20
+ img_array = np.expand_dims(img_array, axis=0)
21
+ return tf.keras.applications.efficientnet.preprocess_input(img_array)
22
+
23
+ @app.route('/')
24
+ def home():
25
+ return render_template('index.html')
26
+
27
+ @app.route('/predict', methods=['POST'])
28
+ def predict():
29
+ if 'file' not in request.files:
30
+ return redirect(request.url)
31
+ file = request.files['file']
32
+ if file.filename == '':
33
+ return redirect(request.url)
34
+
35
+ # Prepare the image for prediction
36
+ img = prepare_image(file)
37
+ res = incept_model.predict(img)
38
+ pred = classes[np.argmax(res)]
39
+
40
+ # Encode image to display in the result page
41
+ file.seek(0) # Reset file pointer to the beginning
42
+ img_bytes = file.read()
43
+ img_base64 = base64.b64encode(img_bytes).decode('utf-8')
44
+ img_data = f"data:image/jpeg;base64,{img_base64}"
45
+
46
+ return render_template('result.html', prediction=pred, image_data=img_data)
47
+
48
+ if __name__ == '__main__':
49
+ app.run(debug=True)
benign.png ADDED
best_model_2.h5 ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:45614d481307c61e7c367907c13bfbaa974bac4c29da00960c7759ae2fadf655
3
+ size 419012240
breast-cancer-awareness-month-1200x834.jpg ADDED
malignant.png ADDED
normal.png ADDED