Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -87,6 +87,18 @@ MODEL_CONFIG = {
|
|
87 |
}
|
88 |
}
|
89 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
90 |
models = {}
|
91 |
|
92 |
def load_all_models():
|
@@ -193,10 +205,16 @@ def serve_test_image(filename):
|
|
193 |
def example_images():
|
194 |
try:
|
195 |
files = []
|
|
|
|
|
196 |
if os.path.isdir(TEST_IMAGES_DIR):
|
197 |
for f in os.listdir(TEST_IMAGES_DIR):
|
198 |
lf = f.lower()
|
199 |
if lf.endswith(('.png', '.jpg', '.jpeg')):
|
|
|
|
|
|
|
|
|
200 |
files.append(url_for('serve_test_image', filename=f))
|
201 |
return jsonify({"images": files})
|
202 |
except Exception as e:
|
|
|
87 |
}
|
88 |
}
|
89 |
|
90 |
+
# Heuristic filename patterns for mapping examples per model
|
91 |
+
MODEL_EXAMPLE_PATTERNS = {
|
92 |
+
"Pneumonia": ["pneumonia", "normal-"],
|
93 |
+
"Tuberculosis": ["tuberculosis", "tb-"],
|
94 |
+
"Brain Tumor": ["glioma", "meningioma", "notumor", "pituitary", "brain"],
|
95 |
+
"Skin Cancer": ["melanoma", "nev", "keratos", "carcinoma", "vascular", "dermatofibroma", "skin"],
|
96 |
+
"Kvasir": [
|
97 |
+
"dyedlifted", "dyedresection", "esophagitis", "normalceacum", "normalpylorus",
|
98 |
+
"normalzline", "polypus", "ulcerative"
|
99 |
+
],
|
100 |
+
}
|
101 |
+
|
102 |
models = {}
|
103 |
|
104 |
def load_all_models():
|
|
|
205 |
def example_images():
|
206 |
try:
|
207 |
files = []
|
208 |
+
selected_model = (request.args.get('model') or '').strip()
|
209 |
+
patterns = MODEL_EXAMPLE_PATTERNS.get(selected_model, []) if selected_model else []
|
210 |
if os.path.isdir(TEST_IMAGES_DIR):
|
211 |
for f in os.listdir(TEST_IMAGES_DIR):
|
212 |
lf = f.lower()
|
213 |
if lf.endswith(('.png', '.jpg', '.jpeg')):
|
214 |
+
# If a model is selected and patterns exist, filter by them
|
215 |
+
if patterns:
|
216 |
+
if not any(p in lf for p in patterns):
|
217 |
+
continue
|
218 |
files.append(url_for('serve_test_image', filename=f))
|
219 |
return jsonify({"images": files})
|
220 |
except Exception as e:
|