Spaces:
Running
Running
Update src/ai_processor.py
Browse files- src/ai_processor.py +3 -70
src/ai_processor.py
CHANGED
|
@@ -242,77 +242,10 @@ class AIProcessor:
|
|
| 242 |
return {'success':False, 'error':str(e)}
|
| 243 |
|
| 244 |
|
| 245 |
-
# Legacy methods for backward compatibility
|
| 246 |
def analyze_wound(self, image, questionnaire_data):
|
| 247 |
-
"""Legacy
|
| 248 |
-
|
| 249 |
-
|
| 250 |
-
if isinstance(image, str):
|
| 251 |
-
try:
|
| 252 |
-
from PIL import Image
|
| 253 |
-
image = Image.open(image)
|
| 254 |
-
logging.info(f"Converted string path to PIL Image: {image}")
|
| 255 |
-
except Exception as e:
|
| 256 |
-
logging.error(f"Error converting string path to image: {e}")
|
| 257 |
-
|
| 258 |
-
# Ensure we have a PIL Image object
|
| 259 |
-
if not isinstance(image, Image.Image):
|
| 260 |
-
try:
|
| 261 |
-
from PIL import Image
|
| 262 |
-
import io
|
| 263 |
-
|
| 264 |
-
# If it's a file-like object
|
| 265 |
-
if hasattr(image, 'read'):
|
| 266 |
-
# Reset file pointer if possible
|
| 267 |
-
if hasattr(image, 'seek'):
|
| 268 |
-
image.seek(0)
|
| 269 |
-
image = Image.open(image)
|
| 270 |
-
logging.info("Converted file-like object to PIL Image")
|
| 271 |
-
except Exception as e:
|
| 272 |
-
logging.error(f"Error ensuring image is PIL Image: {e}")
|
| 273 |
-
raise ValueError(f"Invalid image format: {type(image)}")
|
| 274 |
-
|
| 275 |
-
result = self.full_analysis_pipeline(image, questionnaire_data)
|
| 276 |
-
|
| 277 |
-
if result['success']:
|
| 278 |
-
return {
|
| 279 |
-
'timestamp': result['timestamp'],
|
| 280 |
-
'summary': f"Analysis completed for {questionnaire_data.get('patient_name', 'patient')}",
|
| 281 |
-
'recommendations': result['report'],
|
| 282 |
-
'wound_detection': {
|
| 283 |
-
'status': 'success',
|
| 284 |
-
'detections': [result['visual_analysis']],
|
| 285 |
-
'total_wounds': 1
|
| 286 |
-
},
|
| 287 |
-
'segmentation_result': {
|
| 288 |
-
'status': 'success',
|
| 289 |
-
'wound_area_percentage': result['visual_analysis'].get('surface_area_cm2', 0)
|
| 290 |
-
},
|
| 291 |
-
'risk_assessment': self._assess_risk_legacy(questionnaire_data),
|
| 292 |
-
'guideline_recommendations': [result['report'][:200] + "..."]
|
| 293 |
-
}
|
| 294 |
-
else:
|
| 295 |
-
return {
|
| 296 |
-
'timestamp': result['timestamp'],
|
| 297 |
-
'summary': f"Analysis failed: {result['error']}",
|
| 298 |
-
'recommendations': "Please consult with a healthcare professional.",
|
| 299 |
-
'wound_detection': {'status': 'error', 'message': result['error']},
|
| 300 |
-
'segmentation_result': {'status': 'error', 'message': result['error']},
|
| 301 |
-
'risk_assessment': {'risk_score': 0, 'risk_level': 'Unknown', 'risk_factors': []},
|
| 302 |
-
'guideline_recommendations': ["Analysis unavailable due to error"]
|
| 303 |
-
}
|
| 304 |
-
|
| 305 |
-
except Exception as e:
|
| 306 |
-
logging.error(f"Legacy analyze_wound error: {e}")
|
| 307 |
-
return {
|
| 308 |
-
'timestamp': datetime.now().isoformat(),
|
| 309 |
-
'summary': f"Analysis error: {str(e)}",
|
| 310 |
-
'recommendations': "Please consult with a healthcare professional.",
|
| 311 |
-
'wound_detection': {'status': 'error', 'message': str(e)},
|
| 312 |
-
'segmentation_result': {'status': 'error', 'message': str(e)},
|
| 313 |
-
'risk_assessment': {'risk_score': 0, 'risk_level': 'Unknown', 'risk_factors': []},
|
| 314 |
-
'guideline_recommendations': ["Analysis unavailable due to error"]
|
| 315 |
-
}
|
| 316 |
|
| 317 |
def _assess_risk_legacy(self, questionnaire_data):
|
| 318 |
"""Legacy risk assessment for backward compatibility"""
|
|
|
|
| 242 |
return {'success':False, 'error':str(e)}
|
| 243 |
|
| 244 |
|
|
|
|
| 245 |
def analyze_wound(self, image, questionnaire_data):
|
| 246 |
+
"""Legacy wrapper."""
|
| 247 |
+
if isinstance(image, str): image = Image.open(image)
|
| 248 |
+
return self.full_analysis_pipeline(image, questionnaire_data)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 249 |
|
| 250 |
def _assess_risk_legacy(self, questionnaire_data):
|
| 251 |
"""Legacy risk assessment for backward compatibility"""
|