CGAllenger commited on
Commit
1faf60c
·
verified ·
1 Parent(s): d49804e

show best result only

Browse files
Files changed (1) hide show
  1. app.py +7 -6
app.py CHANGED
@@ -3,7 +3,7 @@ import numpy as np
3
  import tensorflow as tf
4
  from PIL import Image
5
  import efficientnet.tfkeras as efn
6
- import random # <-- Added import for the random adjustment
7
 
8
  # ==========================================
9
  # 1. MRI Model Setup (Your Existing Model)
@@ -31,12 +31,12 @@ def predict_mri(image):
31
  confidences = {}
32
  for i in range(len(mri_class_names)):
33
  original_conf = float(predictions[i])
34
- random_drop = random.uniform(0.03, 0.07) # Random value between 3% and 7%
35
 
36
  # Ensure it doesn't drop below 0
37
  adjusted_conf = max(0.0, original_conf - random_drop)
38
 
39
- # Rounding to 4 decimal places gives 2 decimal digits as a percentage (e.g., 0.9345 -> 93.45%)
40
  confidences[mri_class_names[i]] = round(adjusted_conf, 4)
41
 
42
  return confidences
@@ -92,12 +92,12 @@ def predict_xray(image):
92
  confidences = {}
93
  for i in range(len(xray_class_names)):
94
  original_conf = float(predictions[i])
95
- random_drop = random.uniform(0.03, 0.07) # Random value between 3% and 7%
96
 
97
  # Ensure it doesn't drop below 0
98
  adjusted_conf = max(0.0, original_conf - random_drop)
99
 
100
- # Rounding to 4 decimal places gives 2 decimal digits as a percentage
101
  confidences[xray_class_names[i]] = round(adjusted_conf, 4)
102
 
103
  return confidences
@@ -117,7 +117,8 @@ with gr.Blocks(title="Medical Scan Classification") as interface:
117
  mri_input = gr.Image(label="Upload MRI Brain Scan")
118
  mri_button = gr.Button("Classify MRI", variant="primary")
119
  with gr.Column():
120
- mri_output = gr.Label(num_top_classes=4, label="Prediction Confidence")
 
121
 
122
  mri_button.click(fn=predict_mri, inputs=mri_input, outputs=mri_output)
123
 
 
3
  import tensorflow as tf
4
  from PIL import Image
5
  import efficientnet.tfkeras as efn
6
+ import random
7
 
8
  # ==========================================
9
  # 1. MRI Model Setup (Your Existing Model)
 
31
  confidences = {}
32
  for i in range(len(mri_class_names)):
33
  original_conf = float(predictions[i])
34
+ random_drop = random.uniform(0.03, 0.07)
35
 
36
  # Ensure it doesn't drop below 0
37
  adjusted_conf = max(0.0, original_conf - random_drop)
38
 
39
+ # Rounding to 4 decimal places
40
  confidences[mri_class_names[i]] = round(adjusted_conf, 4)
41
 
42
  return confidences
 
92
  confidences = {}
93
  for i in range(len(xray_class_names)):
94
  original_conf = float(predictions[i])
95
+ random_drop = random.uniform(0.03, 0.07)
96
 
97
  # Ensure it doesn't drop below 0
98
  adjusted_conf = max(0.0, original_conf - random_drop)
99
 
100
+ # Rounding to 4 decimal places
101
  confidences[xray_class_names[i]] = round(adjusted_conf, 4)
102
 
103
  return confidences
 
117
  mri_input = gr.Image(label="Upload MRI Brain Scan")
118
  mri_button = gr.Button("Classify MRI", variant="primary")
119
  with gr.Column():
120
+ # CHANGE APPLIED HERE: num_top_classes changed to 1
121
+ mri_output = gr.Label(num_top_classes=1, label="Top Predicted Condition")
122
 
123
  mri_button.click(fn=predict_mri, inputs=mri_input, outputs=mri_output)
124