|
class MultimodalFusion:
|
|
"""
|
|
Combines insights from image analysis and text analysis
|
|
to provide comprehensive medical assessment
|
|
"""
|
|
|
|
def __init__(self):
|
|
pass
|
|
|
|
def fuse_insights(self, image_results, text_results):
|
|
"""
|
|
Fuse insights from image and text analysis
|
|
|
|
Args:
|
|
image_results (dict): Results from image analysis
|
|
text_results (dict): Results from text analysis
|
|
|
|
Returns:
|
|
dict: Combined insights with recommendation
|
|
"""
|
|
|
|
combined_insights = {
|
|
"Image findings": image_results,
|
|
"Text findings": text_results,
|
|
}
|
|
|
|
|
|
confidence_scores = [
|
|
value for key, value in image_results.items() if isinstance(value, float)
|
|
]
|
|
avg_confidence = (
|
|
sum(confidence_scores) / len(confidence_scores) if confidence_scores else 0
|
|
)
|
|
|
|
|
|
image_abnormal = any(
|
|
key != "No findings" and value > 0.5
|
|
for key, value in image_results.items()
|
|
if isinstance(value, float)
|
|
)
|
|
|
|
|
|
text_concerning = text_results.get("Sentiment") == "Concerning"
|
|
|
|
|
|
if image_abnormal and text_concerning:
|
|
recommendation = "High priority: Both image and text indicate abnormalities"
|
|
elif image_abnormal:
|
|
recommendation = "Medium priority: Image shows potential abnormalities"
|
|
elif text_concerning:
|
|
recommendation = "Medium priority: Text report indicates concerns"
|
|
else:
|
|
recommendation = "Low priority: No significant findings detected"
|
|
|
|
combined_insights["Recommendation"] = recommendation
|
|
combined_insights["Confidence"] = f"{avg_confidence:.2f}"
|
|
|
|
return combined_insights
|
|
|