Spaces:
Runtime error
Runtime error
Update components/CodriaoCore.py
Browse files- components/CodriaoCore.py +7 -14
components/CodriaoCore.py
CHANGED
@@ -1,10 +1,9 @@
|
|
1 |
-
|
2 |
import aiohttp
|
3 |
import json
|
4 |
import logging
|
5 |
import torch
|
6 |
import faiss
|
7 |
-
import numpy
|
8 |
from transformers import AutoModelForCausalLM, AutoTokenizer
|
9 |
from typing import List, Dict, Any
|
10 |
from cryptography.fernet import Fernet
|
@@ -25,13 +24,15 @@ from components.multi_model_analyzer import MultiAgentSystem
|
|
25 |
# Codriao's enhanced modules
|
26 |
from codriao_tb_module import CodriaoHealthModule
|
27 |
from secure_memory_loader import load_secure_memory_module
|
|
|
|
|
|
|
28 |
from ethical_filter import EthicalFilter
|
29 |
from results_store import save_result
|
30 |
|
31 |
# Utilities
|
32 |
from utils.database import Database
|
33 |
from utils.logger import logger
|
34 |
-
from utils.secure_memory_loader import secure_memory_module
|
35 |
|
36 |
class CodriaoCore:
|
37 |
def __init__(self, config_path: str = "config.json"):
|
@@ -45,10 +46,6 @@ class CodriaoCore:
|
|
45 |
self.http_session = aiohttp.ClientSession()
|
46 |
self.database = Database()
|
47 |
|
48 |
-
# 🧠 Replace static SecureMemory with dynamic, temp version
|
49 |
-
secure_memory_module = load_secure_memory_module()
|
50 |
-
SecureMemorySession = secure_memory_module.SecureMemorySession
|
51 |
-
|
52 |
# Cognitive & ethical subsystems
|
53 |
self.sentiment_analyzer = EnhancedSentimentAnalyzer()
|
54 |
self.self_improving_ai = SelfImprovingAI()
|
@@ -75,14 +72,12 @@ class CodriaoCore:
|
|
75 |
|
76 |
async def generate_response(self, query: str, user_id: int) -> Dict[str, Any]:
|
77 |
try:
|
78 |
-
# Ethical Safety
|
79 |
check = self.ethical_filter.analyze_query(query)
|
80 |
if check["status"] == "blocked":
|
81 |
return {"error": check["reason"]}
|
82 |
if check["status"] == "flagged":
|
83 |
logger.warning(check["warning"])
|
84 |
|
85 |
-
# Optional: Trigger TB diagnostics by user request
|
86 |
if any(trigger in query.lower() for trigger in ["tb check", "run tb diagnostics", "tb test"]):
|
87 |
result = await self.run_tb_diagnostics("tb_image.jpg", "tb_cough.wav", user_id)
|
88 |
return result
|
@@ -117,13 +112,11 @@ class CodriaoCore:
|
|
117 |
result_filename = save_result(result)
|
118 |
result["shareable_link"] = f"https://huggingface.co/spaces/Raiff1982/codriao/blob/main/results/{result_filename}"
|
119 |
|
120 |
-
# Auto-escalation for HIGH risk
|
121 |
if result["tb_risk"] == "HIGH":
|
122 |
-
result["next_steps"] = "
|
123 |
elif result["tb_risk"] == "MEDIUM":
|
124 |
-
result["next_steps"] = "
|
125 |
|
126 |
-
# Multi-language support
|
127 |
if language != "en":
|
128 |
try:
|
129 |
translated_result = GoogleTranslator(source="auto", target=language).translate(json.dumps(result))
|
@@ -147,7 +140,7 @@ class CodriaoCore:
|
|
147 |
self.speech_engine.say(response)
|
148 |
self.speech_engine.runAndWait()
|
149 |
except:
|
150 |
-
pass
|
151 |
|
152 |
def generate_jwt(self, user_id: int):
|
153 |
payload = {
|
|
|
|
|
1 |
import aiohttp
|
2 |
import json
|
3 |
import logging
|
4 |
import torch
|
5 |
import faiss
|
6 |
+
import numpy as np
|
7 |
from transformers import AutoModelForCausalLM, AutoTokenizer
|
8 |
from typing import List, Dict, Any
|
9 |
from cryptography.fernet import Fernet
|
|
|
24 |
# Codriao's enhanced modules
|
25 |
from codriao_tb_module import CodriaoHealthModule
|
26 |
from secure_memory_loader import load_secure_memory_module
|
27 |
+
secure_memory = load_secure_memory_module()
|
28 |
+
SecureMemorySession = secure_memory.SecureMemorySession
|
29 |
+
|
30 |
from ethical_filter import EthicalFilter
|
31 |
from results_store import save_result
|
32 |
|
33 |
# Utilities
|
34 |
from utils.database import Database
|
35 |
from utils.logger import logger
|
|
|
36 |
|
37 |
class CodriaoCore:
|
38 |
def __init__(self, config_path: str = "config.json"):
|
|
|
46 |
self.http_session = aiohttp.ClientSession()
|
47 |
self.database = Database()
|
48 |
|
|
|
|
|
|
|
|
|
49 |
# Cognitive & ethical subsystems
|
50 |
self.sentiment_analyzer = EnhancedSentimentAnalyzer()
|
51 |
self.self_improving_ai = SelfImprovingAI()
|
|
|
72 |
|
73 |
async def generate_response(self, query: str, user_id: int) -> Dict[str, Any]:
|
74 |
try:
|
|
|
75 |
check = self.ethical_filter.analyze_query(query)
|
76 |
if check["status"] == "blocked":
|
77 |
return {"error": check["reason"]}
|
78 |
if check["status"] == "flagged":
|
79 |
logger.warning(check["warning"])
|
80 |
|
|
|
81 |
if any(trigger in query.lower() for trigger in ["tb check", "run tb diagnostics", "tb test"]):
|
82 |
result = await self.run_tb_diagnostics("tb_image.jpg", "tb_cough.wav", user_id)
|
83 |
return result
|
|
|
112 |
result_filename = save_result(result)
|
113 |
result["shareable_link"] = f"https://huggingface.co/spaces/Raiff1982/codriao/blob/main/results/{result_filename}"
|
114 |
|
|
|
115 |
if result["tb_risk"] == "HIGH":
|
116 |
+
result["next_steps"] = "⚠️ Immediate follow-up required. Please visit a healthcare provider."
|
117 |
elif result["tb_risk"] == "MEDIUM":
|
118 |
+
result["next_steps"] = "🔍 Consider additional testing for confirmation."
|
119 |
|
|
|
120 |
if language != "en":
|
121 |
try:
|
122 |
translated_result = GoogleTranslator(source="auto", target=language).translate(json.dumps(result))
|
|
|
140 |
self.speech_engine.say(response)
|
141 |
self.speech_engine.runAndWait()
|
142 |
except:
|
143 |
+
pass
|
144 |
|
145 |
def generate_jwt(self, user_id: int):
|
146 |
payload = {
|