Raiff1982 commited on
Commit
a4f8e39
·
verified ·
1 Parent(s): 0627eae

Create codriao_tb_module.py

Browse files
Files changed (1) hide show
  1. codriao_tb_module.py +45 -0
codriao_tb_module.py ADDED
@@ -0,0 +1,45 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import asyncio
2
+ import logging
3
+ from ai_system.ai_core import AICore
4
+ from tb_image_processor import TBImageProcessor
5
+ from tb_audio_processor import TBAudioProcessor
6
+
7
+ logger = logging.getLogger(__name__)
8
+
9
+ class CodriaoHealthModule:
10
+ """Embedded compassionate TB detection within Codriao's architecture"""
11
+
12
+ def __init__(self, ai_core: AICore):
13
+ self.ai_core = ai_core
14
+ self.image_processor = TBImageProcessor()
15
+ self.audio_processor = TBAudioProcessor()
16
+
17
+ async def evaluate_tb_risk(self, image_path: str, audio_path: str, user_id: int):
18
+ image_result, image_confidence = self.image_processor.process_image(image_path)
19
+ audio_result, audio_confidence = self.audio_processor.process_audio(audio_path)
20
+
21
+ if "Error" in [image_result, audio_result]:
22
+ tb_risk = "UNKNOWN"
23
+ elif image_result == "TB Detected" and audio_result == "TB Detected":
24
+ tb_risk = "HIGH"
25
+ elif image_result == "TB Detected" or audio_result == "TB Detected":
26
+ tb_risk = "MEDIUM"
27
+ else:
28
+ tb_risk = "LOW"
29
+
30
+ combined_query = (
31
+ f"Medical Analysis Input: TB image: {image_result} (confidence {image_confidence:.2f}), "
32
+ f"Audio: {audio_result} (confidence {audio_confidence:.2f}). Risk Level: {tb_risk}. "
33
+ f"Please respond with a kind, ethical interpretation and recommended next steps."
34
+ )
35
+
36
+ response = await self.ai_core.generate_response(combined_query, user_id)
37
+
38
+ return {
39
+ "tb_risk": tb_risk,
40
+ "image_analysis": {"result": image_result, "confidence": image_confidence},
41
+ "audio_analysis": {"result": audio_result, "confidence": audio_confidence},
42
+ "ethical_analysis": response.get("response"),
43
+ "explanation": response.get("explanation"),
44
+ "system_health": response.get("health"),
45
+ }