Spaces:
Paused
Paused
Download utils/recommendations.py from MuhammadTechxone/heedxai: direct link, hf CLI and curl.
- Browser
- Download file 2.04 kB
-
https://huggingface.co/spaces/MuhammadTechxone/heedxai/resolve/main/utils/recommendations.py
- Command line
-
hf download hf://spaces/MuhammadTechxone/heedxai/utils/recommendations.py
-
curl -L -o recommendations.py https://huggingface.co/spaces/MuhammadTechxone/heedxai/resolve/main/utils/recommendations.py
2.04 kB
| """ | |
| Recommendation engine based on risk assessment | |
| """ | |
| from config.settings import RECOMMENDATIONS | |
| class RecommendationEngine: | |
| """ | |
| Provides appropriate recommendations based on analysis results | |
| """ | |
| def __init__(self): | |
| self.recommendations = RECOMMENDATIONS | |
| def get_recommendations(self, primary_indicator, risk_level, suicidal_flagged=None): | |
| """ | |
| Get tailored recommendations based on primary indicator and risk level | |
| """ | |
| # Handle high-risk suicidal cases first | |
| if risk_level in ['high', 'moderate_high'] and suicidal_flagged: | |
| return self.recommendations['suicidal'] | |
| # Get recommendations based on primary indicator | |
| if primary_indicator in self.recommendations: | |
| return self.recommendations[primary_indicator] | |
| # Default to normal if unknown | |
| return self.recommendations['normal'] | |
| def get_crisis_resources(self): | |
| """ | |
| Return crisis resources for high-risk situations | |
| """ | |
| return { | |
| 'title': "🚨 Crisis Resources", | |
| 'resources': [ | |
| "**National Emergency Services:** Call 112", | |
| "**Mentally Aware Nigeria Initiative (MANI):** 08062106493", | |
| "**She Writes Woman:** 08099769974", | |
| "**Lagos State Help Line:** 767 or 112" | |
| ], | |
| 'message': "These resources provide immediate, confidential support 24/7." | |
| } | |
| def format_recommendations(self, recommendations_dict): | |
| """ | |
| Format recommendations for display | |
| """ | |
| if not recommendations_dict: | |
| return "" | |
| formatted = f"### {recommendations_dict['title']}\n\n" | |
| formatted += f"{recommendations_dict['message']}\n\n" | |
| for i, tip in enumerate(recommendations_dict['tips'], 1): | |
| formatted += f"{i}. {tip}\n" | |
| return formatted |