andromeda01111 commited on
Commit
a5498d4
·
verified ·
1 Parent(s): 93a5996

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +30 -21
app.py CHANGED
@@ -48,7 +48,7 @@ feature_names = [
48
  "SE Radius", "SE Texture", "SE Perimeter", "SE Area", "SE Smoothness",
49
  "SE Compactness", "SE Concavity", "SE Concave Points", "SE Symmetry", "SE Fractal Dimension",
50
  "Worst Radius", "Worst Texture", "Worst Perimeter", "Worst Area", "Worst Smoothness",
51
- "Worst Compactness", "Worst Concavity", "Worst Concave Points", "Worst Symmetry"
52
  ]
53
 
54
  def classify(model_choice, image=None, file=None, *features):
@@ -73,7 +73,7 @@ def classify(model_choice, image=None, file=None, *features):
73
  except Exception as e:
74
  return f"Error reading file: {e}"
75
 
76
- if any(f is None for f in features):
77
  return "Please provide all 30 numerical features."
78
 
79
  input_data = np.array(features).reshape(1, -1)
@@ -83,24 +83,33 @@ def classify(model_choice, image=None, file=None, *features):
83
 
84
  return class_names[predicted_class]
85
 
86
- # Gradio UI
87
- model_selector = gr.Radio(["ViT", "Neural Network"], label="Choose Model")
88
- image_input = gr.Image(type="pil", label="Upload Mammogram Image")
89
- file_input = gr.File(label="Upload Text File (for NN model)")
90
- feature_inputs = [gr.Number(label=feature) for feature in feature_names]
91
-
92
- # Example inputs from Wisconsin Breast Cancer Dataset
93
- benign_example = ["Neural Network", None, None, 12.32, 12.39, 78.85, 464.1, 0.1028, 0.06981, 0.03987, 0.037, 0.1959, 0.05955, 0.2684, 0.7887, 2.058, 0.02142, 0.01499, 0.01157, 0.01117, 0.01841, 0.003599, 14.34, 14.26, 93.77, 644.8, 0.1288, 0.108, 0.08877, 0.08021, 0.2856, 0.07039]
94
- malignant_example = ["Neural Network", None, None, 20.57, 17.77, 132.9, 1326.0, 0.08474, 0.07864, 0.0869, 0.07017, 0.1812, 0.05667, 0.5435, 0.7339, 3.398, 0.005225, 0.01308, 0.0186, 0.0134, 0.01389, 0.003532, 24.99, 23.41, 158.8, 1956.0, 0.1238, 0.1866, 0.2416, 0.186, 0.275, 0.08902]
95
- example_inputs = [benign_example, malignant_example]
96
-
97
- iface = gr.Interface(
98
- fn=classify,
99
- inputs=[model_selector, image_input, file_input] + feature_inputs,
100
- outputs="text",
101
- title="Breast Cancer Classification",
102
- description="Choose between ViT (image-based) and Neural Network (feature-based) classification. You can upload a text file containing feature values instead of entering them manually.",
103
- examples=example_inputs
104
- )
 
 
 
 
 
 
 
 
 
105
 
106
  iface.launch()
 
48
  "SE Radius", "SE Texture", "SE Perimeter", "SE Area", "SE Smoothness",
49
  "SE Compactness", "SE Concavity", "SE Concave Points", "SE Symmetry", "SE Fractal Dimension",
50
  "Worst Radius", "Worst Texture", "Worst Perimeter", "Worst Area", "Worst Smoothness",
51
+ "Worst Compactness", "Worst Concavity", "Worst Concave Points", "Worst Symmetry", "Worst Fractal Dimension"
52
  ]
53
 
54
  def classify(model_choice, image=None, file=None, *features):
 
73
  except Exception as e:
74
  return f"Error reading file: {e}"
75
 
76
+ if len(features) != len(feature_names):
77
  return "Please provide all 30 numerical features."
78
 
79
  input_data = np.array(features).reshape(1, -1)
 
83
 
84
  return class_names[predicted_class]
85
 
86
+ with gr.Blocks() as iface:
87
+ gr.Markdown("# Breast Cancer Classification")
88
+ gr.Markdown("Choose between ViT (image-based) and Neural Network (feature-based) classification.")
89
+
90
+ with gr.Row():
91
+ model_selector = gr.Radio(["ViT", "Neural Network"], label="Choose Model", interactive=True)
92
+
93
+ with gr.Row():
94
+ with gr.Column():
95
+ image_input = gr.Image(type="pil", label="Upload Mammogram Image")
96
+ file_input = gr.File(label="Upload Text File (for NN model)")
97
+
98
+ with gr.Row():
99
+ gr.Markdown("### Enter Features (For Neural Network Model)")
100
+
101
+ num_cols = 3
102
+ feature_inputs = [gr.Number(label=feature) for feature in feature_names]
103
+ feature_inputs_split = [feature_inputs[i::num_cols] for i in range(num_cols)]
104
+
105
+ with gr.Row():
106
+ for col in feature_inputs_split:
107
+ with gr.Column():
108
+ for feature in col:
109
+ feature.render()
110
+
111
+ output = gr.Textbox(label="Prediction Result")
112
+ classify_button = gr.Button("Classify")
113
+ classify_button.click(classify, inputs=[model_selector, image_input, file_input] + feature_inputs, outputs=output)
114
 
115
  iface.launch()