Spaces:
Sleeping
Sleeping
Commit ·
d1c309d
1
Parent(s): 87bd5bc
Upload folder using huggingface_hub (#18)
Browse files- Upload folder using huggingface_hub (28069d83f12fea0d67844928ca5b6b040aef854a)
Co-authored-by: nicanor zousko <zousko-stark@users.noreply.huggingface.co>
main.py
CHANGED
|
@@ -1022,13 +1022,47 @@ class MedSigClipWrapper:
|
|
| 1022 |
|
| 1023 |
if not qc_result['passed']:
|
| 1024 |
logger.warning(f"⛔ Quality Control Failed: {qc_result['reasons']}")
|
| 1025 |
-
#
|
| 1026 |
-
# ensuring the Frontend shows the error.
|
| 1027 |
enhanced_result['diagnosis'] = "Analyse Refusée (Qualité Insuffisante)"
|
| 1028 |
enhanced_result['confidence'] = 0.0
|
|
|
|
| 1029 |
enhanced_result['quality_failure_reasons'] = qc_result['reasons']
|
| 1030 |
-
|
| 1031 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1032 |
|
| 1033 |
# If QC Passed, Proceed to Explanation
|
| 1034 |
import explainability
|
|
|
|
| 1022 |
|
| 1023 |
if not qc_result['passed']:
|
| 1024 |
logger.warning(f"⛔ Quality Control Failed: {qc_result['reasons']}")
|
| 1025 |
+
# STRICT REJECTION: Override diagnosis and clear predictions
|
|
|
|
| 1026 |
enhanced_result['diagnosis'] = "Analyse Refusée (Qualité Insuffisante)"
|
| 1027 |
enhanced_result['confidence'] = 0.0
|
| 1028 |
+
enhanced_result['specific'] = [] # Clear predictions
|
| 1029 |
enhanced_result['quality_failure_reasons'] = qc_result['reasons']
|
| 1030 |
+
enhanced_result['image_quality'] = {
|
| 1031 |
+
"quality_score": qc_result['quality_score'],
|
| 1032 |
+
"passed": False,
|
| 1033 |
+
"reasons": qc_result['reasons'],
|
| 1034 |
+
"metrics": qc_result['metrics']
|
| 1035 |
+
}
|
| 1036 |
+
|
| 1037 |
+
# FIX: Construct localized_result explicitly as it is not defined yet
|
| 1038 |
+
rejection_result = {
|
| 1039 |
+
"domain": {
|
| 1040 |
+
"label": best_domain_key,
|
| 1041 |
+
"description": MEDICAL_DOMAINS[best_domain_key]['domain_prompt'],
|
| 1042 |
+
"probability": round(best_domain_prob, 2)
|
| 1043 |
+
},
|
| 1044 |
+
"specific": [],
|
| 1045 |
+
"heatmap": None,
|
| 1046 |
+
"original_image": None, # Will be handled by frontend fallback or we can encode it here if mostly wanted
|
| 1047 |
+
"preprocessing": preprocessing_log,
|
| 1048 |
+
"explainability": {
|
| 1049 |
+
"method": "QC Rejection",
|
| 1050 |
+
"reliability": 0.0
|
| 1051 |
+
}
|
| 1052 |
+
}
|
| 1053 |
+
# We merge enhanced info
|
| 1054 |
+
rejection_result.update(enhanced_result)
|
| 1055 |
+
|
| 1056 |
+
# Encode Original Image even on Rejection for Context
|
| 1057 |
+
try:
|
| 1058 |
+
img_tensor = np.array(image).astype(np.float32) / 255.0
|
| 1059 |
+
original_uint8 = (img_tensor * 255).astype(np.uint8)
|
| 1060 |
+
_, buffer_orig = cv2.imencode('.png', cv2.cvtColor(original_uint8, cv2.COLOR_RGB2BGR))
|
| 1061 |
+
rejection_result["original_image"] = base64.b64encode(buffer_orig).decode('utf-8')
|
| 1062 |
+
except:
|
| 1063 |
+
pass
|
| 1064 |
+
|
| 1065 |
+
return rejection_result
|
| 1066 |
|
| 1067 |
# If QC Passed, Proceed to Explanation
|
| 1068 |
import explainability
|