selva1909 commited on
Commit
efdad1a
·
verified ·
1 Parent(s): 2366773

Upload 3 files

Browse files
Files changed (4) hide show
  1. .gitattributes +1 -0
  2. Best_Model_On_Partial.keras +3 -0
  3. app.py +67 -0
  4. requirements.txt +1 -1
.gitattributes CHANGED
@@ -33,3 +33,4 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
33
  *.zip filter=lfs diff=lfs merge=lfs -text
34
  *.zst filter=lfs diff=lfs merge=lfs -text
35
  *tfevents* filter=lfs diff=lfs merge=lfs -text
 
 
33
  *.zip filter=lfs diff=lfs merge=lfs -text
34
  *.zst filter=lfs diff=lfs merge=lfs -text
35
  *tfevents* filter=lfs diff=lfs merge=lfs -text
36
+ Best_Model_On_Partial.keras filter=lfs diff=lfs merge=lfs -text
Best_Model_On_Partial.keras ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:3e168c670b5d153c0d8e128502f34c2330b337536636866ec43d7b973fcfe285
3
+ size 283521382
app.py ADDED
@@ -0,0 +1,67 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import tensorflow as tf
3
+ import numpy as np
4
+ from PIL import Image
5
+
6
+ # Load the trained model
7
+ model = tf.keras.models.load_model("Best_Model_On_Partial.keras")
8
+
9
+ # Class labels
10
+ class_labels = ['Glioma', 'Meningioma', 'No Tumor', 'Pituitary']
11
+
12
+ # Image preprocessing function
13
+ def preprocess_image(image):
14
+ image = image.convert("RGB")
15
+ image = image.resize((224, 224))
16
+ image = np.array(image) / 255.0 # Normalize
17
+ image = np.expand_dims(image, axis=0) # Add batch dimension
18
+ return image
19
+
20
+ # Prediction function
21
+ def predict(image):
22
+ processed_image = preprocess_image(image)
23
+ prediction = model.predict(processed_image)
24
+ predicted_class = np.argmax(prediction)
25
+ confidence = np.max(prediction) * 100
26
+
27
+ return f"🧠 Prediction: {class_labels[predicted_class]} (Confidence: {confidence:.2f}%)"
28
+
29
+ # Customizing Gradio UI
30
+ custom_css = """
31
+ body {background-color: #1A1F3B; color: #E0E0E0; font-family: Arial, sans-serif;}
32
+ .gradio-container {max-width: 800px; margin: auto; text-align: center;}
33
+ .gr-button {background-color: #007BFF !important; color: white !important; border-radius: 8px;}
34
+ .gr-box {background-color: #2C3E50; padding: 10px; border-radius: 10px;}
35
+ """
36
+
37
+ description = """
38
+ 🧠 **Brain Tumor Detector**
39
+ Upload an MRI scan to classify brain tumors using deep learning.
40
+ 💡 **Supports:** Glioma | Meningioma | No Tumor | Pituitary
41
+ 🚀 **Fast & Accurate AI Model**
42
+ """
43
+
44
+ with gr.Blocks() as interface:
45
+ gr.HTML("<img src='Figure 2025-01-07 031757 (8).png' style='width:100px; position:absolute; top:10px; left:10px;'>")
46
+ gr.Markdown("## Brain Tumor Detection 🧠")
47
+ image = gr.Image(type="pil", label="Upload Brain MRI")
48
+ output = gr.Textbox(label="Prediction")
49
+ btn = gr.Button("Predict")
50
+
51
+ btn.click(predict, inputs=image, outputs=output)
52
+
53
+ # UI Interface
54
+ interface = gr.Interface(
55
+ fn=predict,
56
+ inputs=gr.Image(type="pil", label="Upload Brain MRI"),
57
+ outputs=gr.Textbox(label="Prediction"),
58
+ title="Brain Tumor Detection 🧠",
59
+ description="Upload an MRI scan to classify brain tumors using deep learning.",
60
+ theme="default",
61
+ css=custom_css,
62
+ examples=["/mnt/data/2.webp"] # Use the uploaded image as an example
63
+ )
64
+
65
+ # Launch the app
66
+ interface.launch()
67
+
requirements.txt CHANGED
@@ -1,4 +1,4 @@
1
- gradio
2
  tensorflow
 
3
  numpy
4
  pillow
 
 
1
  tensorflow
2
+ gradio
3
  numpy
4
  pillow