Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -51,8 +51,8 @@ feature_names = [
|
|
51 |
"Worst Compactness", "Worst Concavity", "Worst Concave Points", "Worst Symmetry", "Worst Fractal Dimension"
|
52 |
]
|
53 |
|
54 |
-
def classify(model_choice, image=None, *features):
|
55 |
-
"""Classify using ViT (image) or NN (features)."""
|
56 |
if model_choice == "ViT":
|
57 |
if image is None:
|
58 |
return "Please upload an image for ViT classification."
|
@@ -66,8 +66,15 @@ def classify(model_choice, image=None, *features):
|
|
66 |
return class_names[predicted_class]
|
67 |
|
68 |
elif model_choice == "Neural Network":
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
69 |
if any(f is None for f in features):
|
70 |
-
return "Please
|
71 |
|
72 |
input_data = np.array(features).reshape(1, -1)
|
73 |
input_data_std = scaler.transform(input_data) if scaler else input_data
|
@@ -79,14 +86,21 @@ def classify(model_choice, image=None, *features):
|
|
79 |
# Gradio UI
|
80 |
model_selector = gr.Radio(["ViT", "Neural Network"], label="Choose Model")
|
81 |
image_input = gr.Image(type="pil", label="Upload Mammogram Image")
|
|
|
82 |
feature_inputs = [gr.Number(label=feature) for feature in feature_names]
|
83 |
|
|
|
|
|
|
|
|
|
|
|
84 |
iface = gr.Interface(
|
85 |
fn=classify,
|
86 |
-
inputs=[model_selector, image_input] + feature_inputs,
|
87 |
outputs="text",
|
88 |
title="Breast Cancer Classification",
|
89 |
-
description="Choose between ViT (image-based) and Neural Network (feature-based) classification."
|
|
|
90 |
)
|
91 |
|
92 |
-
iface.launch()
|
|
|
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):
|
55 |
+
"""Classify using ViT (image) or NN (features from manual input or file)."""
|
56 |
if model_choice == "ViT":
|
57 |
if image is None:
|
58 |
return "Please upload an image for ViT classification."
|
|
|
66 |
return class_names[predicted_class]
|
67 |
|
68 |
elif model_choice == "Neural Network":
|
69 |
+
if file is not None:
|
70 |
+
try:
|
71 |
+
file_data = file.read().decode("utf-8").strip().split(',')
|
72 |
+
features = [float(x) for x in file_data]
|
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)
|
80 |
input_data_std = scaler.transform(input_data) if scaler else input_data
|
|
|
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()
|