bbfbfb
Browse files- README.md +7 -0
- medical_ai.py +26 -15
README.md
CHANGED
|
@@ -44,6 +44,13 @@ A multilingual medical consultation AI assistant optimized for Hugging Face Spac
|
|
| 44 |
"language": "fr"
|
| 45 |
}
|
| 46 |
```
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 47 |
|
| 48 |
## 🔧 API Endpoints
|
| 49 |
|
|
|
|
| 44 |
"language": "fr"
|
| 45 |
}
|
| 46 |
```
|
| 47 |
+
### Other Consultation
|
| 48 |
+
```json
|
| 49 |
+
{
|
| 50 |
+
"question": "Quels sont les symptômes du paludisme?",
|
| 51 |
+
"language": "auto"
|
| 52 |
+
}
|
| 53 |
+
```
|
| 54 |
|
| 55 |
## 🔧 API Endpoints
|
| 56 |
|
medical_ai.py
CHANGED
|
@@ -449,34 +449,38 @@ Expert medical response (structured and comprehensive):"""
|
|
| 449 |
return response.strip()
|
| 450 |
|
| 451 |
def _expert_fallback_response(self, question: str, contexts: Dict[str, List[str]], lang: str) -> str:
|
| 452 |
-
"""Réponse de fallback de niveau expert"""
|
| 453 |
-
|
| 454 |
templates = {
|
| 455 |
"en": {
|
| 456 |
-
"intro": "
|
| 457 |
-
"structure":
|
| 458 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 459 |
},
|
| 460 |
"fr": {
|
| 461 |
-
"intro": "
|
| 462 |
-
"structure":
|
| 463 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 464 |
}
|
| 465 |
}
|
| 466 |
-
|
| 467 |
template = templates.get(lang, templates["en"])
|
| 468 |
response = template["intro"]
|
| 469 |
-
|
| 470 |
-
# Intégrer contextes si disponibles
|
| 471 |
all_contexts = []
|
| 472 |
for context_list in contexts.values():
|
| 473 |
all_contexts.extend(context_list)
|
| 474 |
-
|
| 475 |
if all_contexts:
|
| 476 |
response += f" {template['context_available']}{' | '.join(all_contexts[:2])}"
|
| 477 |
-
|
| 478 |
response += template["structure"]
|
| 479 |
-
|
| 480 |
return response
|
| 481 |
|
| 482 |
# === PIPELINE PRINCIPAL COMPÉTITION ===
|
|
@@ -533,7 +537,14 @@ class CompetitionMedicalAIPipeline:
|
|
| 533 |
|
| 534 |
except Exception as e:
|
| 535 |
logger.error(f"Competition processing error: {str(e)}")
|
| 536 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 537 |
|
| 538 |
def _empty_question_response(self, user_lang: str) -> Dict[str, Any]:
|
| 539 |
"""Réponse pour question vide"""
|
|
|
|
| 449 |
return response.strip()
|
| 450 |
|
| 451 |
def _expert_fallback_response(self, question: str, contexts: Dict[str, List[str]], lang: str) -> str:
|
| 452 |
+
"""Réponse de fallback de niveau expert, amicale et dans la langue détectée"""
|
|
|
|
| 453 |
templates = {
|
| 454 |
"en": {
|
| 455 |
+
"intro": "Thank you for your question! I'm here to help you with your health concerns.",
|
| 456 |
+
"structure": (
|
| 457 |
+
"\n\n🔍 Assessment: It looks like you have a medical question that deserves careful attention."
|
| 458 |
+
"\n\n💡 Friendly Advice: Please keep an eye on your symptoms, take care of yourself, and don't hesitate to reach out to a healthcare professional if you feel unwell."
|
| 459 |
+
"\n\n⚠️ Important: For a precise diagnosis and treatment, it's always best to consult a qualified healthcare provider. Take care!"
|
| 460 |
+
),
|
| 461 |
+
"context_available": "According to medical information: "
|
| 462 |
},
|
| 463 |
"fr": {
|
| 464 |
+
"intro": "Merci pour votre question ! Je suis là pour vous aider avec vos préoccupations de santé.",
|
| 465 |
+
"structure": (
|
| 466 |
+
"\n\n🔍 Évaluation : Il semble que vous ayez une question médicale qui mérite toute notre attention."
|
| 467 |
+
"\n\n💡 Conseil amical : Surveillez vos symptômes, prenez soin de vous, et n'hésitez pas à consulter un professionnel de santé si vous ne vous sentez pas bien."
|
| 468 |
+
"\n\n⚠️ Important : Pour un diagnostic et un traitement précis, il est toujours préférable de consulter un professionnel de santé qualifié. Prenez soin de vous !"
|
| 469 |
+
),
|
| 470 |
+
"context_available": "Selon les informations médicales : "
|
| 471 |
}
|
| 472 |
}
|
|
|
|
| 473 |
template = templates.get(lang, templates["en"])
|
| 474 |
response = template["intro"]
|
| 475 |
+
|
|
|
|
| 476 |
all_contexts = []
|
| 477 |
for context_list in contexts.values():
|
| 478 |
all_contexts.extend(context_list)
|
| 479 |
+
|
| 480 |
if all_contexts:
|
| 481 |
response += f" {template['context_available']}{' | '.join(all_contexts[:2])}"
|
| 482 |
+
|
| 483 |
response += template["structure"]
|
|
|
|
| 484 |
return response
|
| 485 |
|
| 486 |
# === PIPELINE PRINCIPAL COMPÉTITION ===
|
|
|
|
| 537 |
|
| 538 |
except Exception as e:
|
| 539 |
logger.error(f"Competition processing error: {str(e)}")
|
| 540 |
+
# Always use detected_lang for fallback, default to 'en' if not available
|
| 541 |
+
fallback_lang = detected_lang if detected_lang in ["en", "fr"] else "en"
|
| 542 |
+
return {
|
| 543 |
+
"response": self._expert_fallback_response(question, {}, fallback_lang),
|
| 544 |
+
"source_lang": fallback_lang,
|
| 545 |
+
"context_used": [],
|
| 546 |
+
"confidence": "medium"
|
| 547 |
+
}
|
| 548 |
|
| 549 |
def _empty_question_response(self, user_lang: str) -> Dict[str, Any]:
|
| 550 |
"""Réponse pour question vide"""
|