Spaces:
Sleeping
Sleeping
Update app.py
Browse files
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
|
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 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
-
|
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()
|