edtech07 commited on
Commit
e85eb16
·
verified ·
1 Parent(s): f917317

Upload folder using huggingface_hub

Browse files
Files changed (4) hide show
  1. .gitattributes +1 -0
  2. README.md +3 -9
  3. app.py +50 -0
  4. my_model.keras +3 -0
.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
+ my_model.keras filter=lfs diff=lfs merge=lfs -text
README.md CHANGED
@@ -1,12 +1,6 @@
1
  ---
2
- title: Mri Tumor Classifier Space
3
- emoji: 💻
4
- colorFrom: red
5
- colorTo: purple
6
- sdk: gradio
7
- sdk_version: 6.0.1
8
  app_file: app.py
9
- pinned: false
 
10
  ---
11
-
12
- Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
1
  ---
2
+ title: mri_tumor_classifier_space
 
 
 
 
 
3
  app_file: app.py
4
+ sdk: gradio
5
+ sdk_version: 5.50.0
6
  ---
 
 
app.py ADDED
@@ -0,0 +1,50 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ import gradio as gr
3
+ import tensorflow as tf
4
+ import numpy as np
5
+ from PIL import Image
6
+ import os
7
+
8
+ # Load the trained model
9
+ model = tf.keras.models.load_model('my_model.keras')
10
+
11
+ # These should be defined if not coming from `train.class_indices`
12
+ # Make sure idx_to_class is available or manually define it if `train` is not accessible
13
+ idx_to_class = {0: 'glioma', 1: 'meningioma', 2: 'notumor', 3: 'pituitary'} # Replace with your actual mapping
14
+ class_labels = list(idx_to_class.values())
15
+
16
+ # Define the image size used for training
17
+ img_size = 224
18
+
19
+ def predict_image(image):
20
+ img = Image.fromarray(image)
21
+ img = img.resize((img_size, img_size))
22
+ img_array = np.array(img)
23
+ img_array = np.expand_dims(img_array, axis=0)
24
+ img_array = tf.keras.applications.efficientnet.preprocess_input(img_array)
25
+
26
+ predictions = model.predict(img_array)[0]
27
+ predicted_class_idx = np.argmax(predictions)
28
+ predicted_class_label = class_labels[predicted_class_idx]
29
+ confidence = predictions[predicted_class_idx] * 100
30
+
31
+ return predicted_class_label, f"{confidence:.2f}%"
32
+
33
+ # Create the Gradio interface
34
+ iface = gr.Interface(
35
+ fn=predict_image,
36
+ inputs=gr.Image(type="numpy", label="Upload MRI Scan"),
37
+ outputs=[
38
+ gr.Textbox(label="Predicted Class"),
39
+ gr.Textbox(label="Confidence")
40
+ ],
41
+ title="Brain Tumor MRI Classification",
42
+ description="Upload an MRI scan to get a prediction for brain tumor type and confidence.",
43
+ examples=[
44
+ os.path.join("/kaggle/input/brain-tumor-mri-dataset/Testing/notumor/Te-no_0015.jpg"),
45
+ os.path.join("/kaggle/input/brain-tumor-mri-dataset/Testing/glioma/Te-gl_0010.jpg")
46
+ ]
47
+ )
48
+
49
+ # This launch is for local testing, not for deployment via `gradio deploy`
50
+ # iface.launch(debug=True, allowed_paths=[test_dir])
my_model.keras ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:02ca582a67a6ced9e99cf91846b948945506bf9eb81c0b5e845c41834a3abd6c
3
+ size 39315228