Update app.py
Browse files
app.py
CHANGED
@@ -11,19 +11,28 @@ app = FastAPI()
|
|
11 |
# Chargement des modèles
|
12 |
def load_models():
|
13 |
return {
|
14 |
-
"chest_classifier": pipeline("image-classification", model="codewithdark/vit-chest-xray")
|
15 |
}
|
16 |
|
17 |
models = load_models()
|
18 |
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
27 |
return translations.get(label, label)
|
28 |
|
29 |
def image_to_base64(image):
|
@@ -248,7 +257,7 @@ async def analyze_file(file: UploadFile = File(...)):
|
|
248 |
results_html += f"""
|
249 |
<div>
|
250 |
<span class="{confidence_class}">{pred['score']:.1%}</span> -
|
251 |
-
{translate_label(pred['label'])}
|
252 |
</div>
|
253 |
"""
|
254 |
|
|
|
11 |
# Chargement des modèles
|
12 |
def load_models():
|
13 |
return {
|
14 |
+
"chest_classifier": pipeline("image-classification", model="codewithdark/vit-chest-xray", use_labels=True)
|
15 |
}
|
16 |
|
17 |
models = load_models()
|
18 |
|
19 |
+
# Liste des maladies dans l'ordre des labels du modèle
|
20 |
+
LABEL_MAP = [
|
21 |
+
'Kardiomegalie', # Élargissement du cœur
|
22 |
+
'Ödem', # Œdème
|
23 |
+
'Konsolidierung', # Consolidation
|
24 |
+
'Lungenentzündung', # Pneumonie
|
25 |
+
'Kein Befund' # Aucune anomalie
|
26 |
+
]
|
27 |
+
|
28 |
+
def translate_label(index):
|
29 |
+
try:
|
30 |
+
# Convertir en entier si c'est une chaîne (ex: "LABEL_1" -> 1)
|
31 |
+
if isinstance(index, str) and index.startswith('LABEL_'):
|
32 |
+
index = int(index.split('_')[1]) - 1
|
33 |
+
return LABEL_MAP[index]
|
34 |
+
except (ValueError, IndexError):
|
35 |
+
return f"Unbekannt ({index})"
|
36 |
return translations.get(label, label)
|
37 |
|
38 |
def image_to_base64(image):
|
|
|
257 |
results_html += f"""
|
258 |
<div>
|
259 |
<span class="{confidence_class}">{pred['score']:.1%}</span> -
|
260 |
+
{translate_label(pred['label'] if isinstance(pred['label'], (int, str)) else pred['label'].item())}
|
261 |
</div>
|
262 |
"""
|
263 |
|