ma4389 commited on
Commit
be50dc6
·
verified ·
1 Parent(s): e5ce5fd

Upload 3 files

Browse files
Files changed (3) hide show
  1. app.py +44 -0
  2. best_model.h5 +3 -0
  3. reqruirements.txt +4 -0
app.py ADDED
@@ -0,0 +1,44 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import tensorflow as tf
3
+ import numpy as np
4
+ from tensorflow.keras.applications.inception_v3 import preprocess_input
5
+ from tensorflow.keras.preprocessing.image import img_to_array
6
+
7
+ # Load the trained model
8
+ model = tf.keras.models.load_model("best_model.h5")
9
+
10
+ # Original class names from directory
11
+ class_names = ["no", "yes"]
12
+
13
+ # Mapping to user-friendly labels
14
+ label_mapping = {
15
+ "no": "No Tumor",
16
+ "yes": "Yes, that's a Brain Tumor"
17
+ }
18
+
19
+ # Prediction function
20
+ def predict(image):
21
+ image = image.resize((224, 224))
22
+ image = img_to_array(image)
23
+ image = np.expand_dims(image, axis=0)
24
+ image = preprocess_input(image)
25
+
26
+ preds = model.predict(image)[0]
27
+ label_idx = np.argmax(preds)
28
+ raw_label = class_names[label_idx]
29
+ readable_label = label_mapping[raw_label]
30
+ confidence = float(preds[label_idx])
31
+
32
+ return {readable_label: confidence}
33
+
34
+ # Gradio Interface
35
+ interface = gr.Interface(
36
+ fn=predict,
37
+ inputs=gr.Image(type="pil"),
38
+ outputs=gr.Label(num_top_classes=2),
39
+ title="🧠 Brain Tumor Detection",
40
+ description="Upload an MRI image to detect if it has a brain tumor using InceptionV3."
41
+ )
42
+
43
+ if __name__ == "__main__":
44
+ interface.launch()
best_model.h5 ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:ca23e7da4b6b7c526471438a046444712c22488eb11ddcb29763280d3af7a308
3
+ size 142858160
reqruirements.txt ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ tensorflow
2
+ gradio
3
+ numpy
4
+ pillow