CoolFace
Apppublic

abdulnim/GRC_framework

sourceHugging Faceapache-2.0updated 3y agoView on Hugging Face
0likes
utils.py351 linesDownload Raw Back to root
1 2 3ai_audit_analysis_categories = {4    "AI Audit": [5        "sentiment_analysis", 6        "emotion_detection", 7        "political_bias_detection", 8        "stress_level_detection",9        "empathy_level_assessment",10        "mood_detection",11        "toxicity_detection"12        ],13 14    "GDPR": [15        "Privacy_Assessment",16        "Consent_and_Transparency", 17        "Data_Security",18        "Environmental_Impact"],19 20    "Toxicity": [21        "Content_Moderation", 22        "Reporting_Mechanism", 23        "Content_Guidelines", 24        "User_Education"],25 26    "Legal": [27        "Privacy_Policy", 28        "Data_Retention", 29        "Consent_Mechanism"],30 31    "Context": [32        "Ethical_AI", 33        "Bais_Mitigation", 34        "Fairness_Assestment", 35        "Explainability"],36 37    "Governance": [38        "Model_development", 39        "Data_Quality", 40        "Bais_Mitigation", 41        "Fairness_Assestment"42        "Explainability"43        "User_Input"],44 45    "RiskManagement": [46     "Corporate_Ethics", 47     "Board_Management", 48     "Stakeholder_Engagement"],49    50    "Robustness": [51        "System_Reliability", 52        "Quality_Assurance", 53        "Stress_Testing", 54        "Fail_Safe_Procedures"],55 56    "Sustainability": [57        "Renewable_Resources", 58        "Waste_Reduction", 59        "Energy_Efficiency", 60        "Sustainable_Practices"]61}62 63 64# Define a standard template for prompts65STANDARD_PROMPT_TEMPLATE = "You are a data analysis assistant capable of {analysis_type} analysis. {specific_instruction} Respond with your analysis in JSON format. The JSON schema should include '{json_schema}'."66 67 68 69 70def get_system_prompt(analysis_type: str) -> str:71    specific_instruction = ANALYSIS_TYPES.get(analysis_type, "Perform the analysis as per the specified type.")72    json_schema = JSON_SCHEMAS.get(analysis_type, {})73    json_schema_str = ', '.join([f"'{key}': {value}" for key, value in json_schema.items()])74    return (f"You are a data analyst API capable of {analysis_type} analysis. "75            f"{specific_instruction} Please respond with your analysis directly in JSON format "76            f"(without using Markdown code blocks or any other formatting). Always include confidence_score:number (0-1) with two decimals for result based on analysis"77            f"The JSON schema should include: {{{json_schema_str}}}.")78 79 80 81 82ANALYSIS_TYPES = {83    "sentiment_analysis": "Analyze the sentiment of the provided text. Determine whether the sentiment is positive, negative, or neutral and provide a confidence score.",84    "emotion_detection": "Detect and identify the primary emotions expressed in the provided text. Provide a score for the intensity of the detected emotion.",85    "political_bias_detection": "Detect any political bias in the provided text, identifying leaning towards particular ideologies or parties.",86    "stress_level_detection": "Analyze the text to assess stress levels, identifying triggers and intensity of stress.",87    "empathy_level_assessment": "Assess the level of empathy expressed in the text, identifying empathetic responses and tendencies.",88    "mood_detection": "Detect the mood of the individual based on textual cues, ranging from happy to sad, calm to angry.",89    "toxicity_detection": "Identify and assess the level of toxicity in the provided text. Determine whether the text contains harmful, offensive, or inappropriate content and provide a score indicating the severity of the toxicity",90 91     # GDPR-related types92    "Consent_and_Transparency": "Evaluate how consent is obtained and the level of transparency provided to users regarding data usage.",93    "Data_Security": "Assess the measures in place for data security, including vulnerabilities and compliance with security standards.",94    "Privacy_Assessment": "Analyze the overall privacy practices, including policy compliance, data minimization, and user data accessibility.",95    "Environmental_Impact": "Assess the environmental impact of data processing practices, including carbon footprint and energy efficiency.",96 97    # Toxicity-related types98    "Content_Moderation": "Evaluate the effectiveness of content moderation practices, including automated and human moderation efforts.",99    "Reporting_Mechanism": "Assess the ease and effectiveness of reporting mechanisms for inappropriate or harmful content.",100    "Content_Guidelines": "Analyze the clarity and comprehensiveness of content guidelines and their enforcement consistency.",101    "User_Education": "Evaluate the availability and accessibility of educational resources for users regarding appropriate content and behavior.",102 103    # Legal-related types104    "Privacy_Policy": "Analyze the clarity and compliance of a privacy policy with legal standards.",105    "Data_Retention": "Evaluate the data retention practices, including periods, deletion policies, and legal compliance.",106    "Consent_Mechanism": "Assess the clarity and effectiveness of the consent mechanism in place for data collection and usage.",107    "GDPR_Compliance": "Evaluate the level of GDPR compliance in data handling, protection measures, and breach notification protocols.",108 109    # Context-related types110    "Ethical_AI": "Assess adherence to ethical standards in AI practices, including identification and mitigation of ethical issues.",111    "Bias_Mitigation": "Evaluate the presence and mitigation of bias in data or algorithms.",112    "Fairness_Assessment": "Assess fairness in AI systems, identifying affected groups and providing recommendations for improvement.",113    "Explainability": "Evaluate the transparency and explainability of AI models to users.",114 115    # Governance-related types116    "Model_Development": "Analyze the process of model development, including team composition and ethical considerations.",117    "Data_Quality": "Assess the quality of data used, focusing on accuracy, completeness, and timeliness.",118    "User_Input": "Evaluate the mechanisms for and impact of user feedback on the system.",119 120    # Risk Management-related types121    "Corporate_Ethics": "Assess the ethical practices within a corporation, including employee training and ethics code adherence.",122    "Board_Management": "Evaluate the effectiveness and diversity of board management and its compliance with ethical standards.",123    "Stakeholder_Engagement": "Analyze stakeholder engagement practices, including inclusion, feedback mechanisms, and satisfaction.",124    "Risk_Management": "Assess the identification, mitigation, and monitoring of risks within an organization.",125 126    # Robustness-related types127    "System_Reliability": "Evaluate the reliability and resilience of a system, including uptime and redundancy measures.",128    "Quality_Assurance": "Assess the quality assurance practices, including compliance with standards and testing frequency.",129    "Stress_Testing": "Analyze the system's robustness through stress testing and identify weaknesses.",130    "Fail_Safe_Procedures": "Evaluate the effectiveness of fail-safe procedures in place for system failures.",131 132    # Sustainability-related types133    "Renewable_Resources": "Assess the use of renewable resources and sustainability goals in operations.",134    "Waste_Reduction": "Evaluate waste management practices, reduction rates, and recycling initiatives.",135    "Energy_Efficiency": "Analyze energy consumption and efficiency, including energy-saving measures and audits.",136    "Sustainable_Practices": "Evaluate the adoption of sustainable practices, including training and overall impact."137}138 139 140JSON_SCHEMAS = {141 142    "sentiment_analysis": {143         "sentiment": "string (positive, negative, neutral)",144         "confidence_score": "number (0-1)",145         "text_snippets": "array of strings (specific text portions contributing to sentiment)"146     },147    "emotion_detection": {148         "emotion": "string (primary emotion detected)",149         "confidence_score": "number (0-1)",150         "secondary_emotions": "array of objects (secondary emotions and their scores)"151     },152     "political_bias_detection": {153         "bias": "string (left, right, neutral)",154         "confidence_score": "number (0-1)",155         "bias_indicators": "array of strings (elements indicating bias)",156         "political_alignment_score": "number (quantifying degree of political bias)"157     },158     "stress_level_detection": {159         "stress_level": "string", 160         "stress_triggers": "array of strings"161     },162    "empathy_level_assessment": {163         "empathy_level": "string", 164         "empathetic_responses": "array of strings"165     },166     "mood_detection": {167         "mood": "string", 168         "mood_intensity": "number"169     },170     "toxicity_detection": {171         "toxicity_level": "string (none, low, medium, high)",172         "toxicity_flags": "array of strings (specific words or phrases contributing to toxicity)",173         "contextual_factors": "array of objects (additional contextual elements influencing toxicity interpretation)"174     },175 176     # GDPR-related schemas177    "Consent_and_Transparency": {178        "consent_obtained": "boolean",179        "transparency_level": "string (low, medium, high)",180        "missing_information": "array of strings (information not clearly presented or missing)",181        "user_understanding": "string (poor, average, good)"182    },183    "Data_Security": {184        "security_status": "string (secure, at risk, breached)",185        "vulnerability_points": "array of strings (specific areas of potential vulnerability)",186        "data_encryption": "boolean",187        "compliance_status": "string (compliant, partially compliant, non-compliant)"188    },189    "Environmental_Impact": {190        "carbon_footprint": "number (metric tons of CO2 equivalent)",191        "energy_efficiency": "string (low, moderate, high)",192        "sustainable_practices": "boolean",193        "environmental_impact_score": "number (0-100)"194    },195   "Privacy_Assessment": {196        "overall_privacy_status": "string (positive, negative)" ,197        "privacy_policy_compliance": "string (compliant, partially compliant, non-compliant)",198        "data_minimization": "boolean",199        "user_data_accessibility": "string (none, limited, full)",200        "anonymization": "boolean"201    },202 203    # Toxicity-related schemas204    "Content_Moderation": {205        "moderation_effectiveness": "string (low, medium, high)",206        "moderated_content_types": "array of strings (types of content being moderated)",207        "automated_moderation": "boolean",208        "human_moderation": "boolean"209    },210    "Reporting_Mechanism": {211        "reporting_ease": "string (easy, moderate, difficult)",212        "response_time": "string (fast, average, slow)",213        "report_feedback": "string (detailed, minimal, none)"214    },215    "Content_Guidelines": {216        "clarity": "string (clear, somewhat clear, unclear)",217        "comprehensiveness": "string (comprehensive, partial, lacking)",218        "enforcement_consistency": "string (consistent, inconsistent)"219    },220    "User_Education": {221        "educational_resources_available": "boolean",222        "resource_accessibility": "string (easy, moderate, difficult)",223        "user_comprehension_level": "string (high, medium, low)"224    },225 226      # Legal-related schemas227    "Privacy_Policy": {228        "clarity": "string (clear, somewhat clear, unclear)",229        "compliance": "string (compliant, partially compliant, non-compliant)",230        "user_rights": "array of strings (specific rights mentioned in policy)"231    },232    "Consent_Mechanism": {233        "mechanism_clarity": "string (clear, somewhat clear, unclear)",234        "user_control": "boolean",235        "opt_in_out": "string (opt-in, opt-out, not applicable)"236    },237    "GDPR_Compliance": {238        "compliance_level": "string (fully compliant, partially compliant, non-compliant)",239        "data_protection_officer": "boolean",240        "breach_notification": "boolean"241    },242 243    # Context-related schemas244    "Ethical_AI": {245        "ethical_standards_adherence": "string (high, medium, low)",246        "ethical_issues_identified": "array of strings",247        "mitigation_measures": "array of strings"248    },249    "Bias_Mitigation": {250        "bias_identified": "boolean",251        "bias_types": "array of strings",252        "mitigation_strategies": "array of strings"253    },254    "Fairness_Assessment": {255        "fairness_level": "string (high, medium, low)",256        "affected_groups": "array of strings",257        "improvement_recommendations": "array of strings"258    },259    "Explainability": {260        "model_transparency": "string (transparent, opaque)",261        "explanation_comprehensibility": "string (high, medium, low)",262        "user_friendly_explanations": "boolean"263    },264 265    # Governance-related schemas266    "Model_Development": {267        "development_process": "string (structured, ad-hoc, undefined)",268        "team_composition": "array of strings (roles involved)",269        "ethics_considerations": "boolean"270    },271    "Data_Quality": {272        "accuracy_level": "string (high, medium, low)",273        "completeness": "string (complete, partial, incomplete)",274        "timeliness": "string (up-to-date, outdated)"275    },276    "User_Input": {277        "user_feedback_mechanism": "boolean",278        "feedback_responsiveness": "string (responsive, moderately responsive, unresponsive)",279        "user_input_impact": "string (high, medium, low)"280    },281 282    # Risk Management-related schemas283    "Corporate_Ethics": {284        "ethics_code": "string (exists, partial, none)",285        "employee_training": "boolean",286        "ethics_violations": "array of strings"287    },288    "Board_Management": {289        "board_structure": "string (effective, average, ineffective)",290        "board_diversity": "boolean",291        "board_ethics_compliance": "string (compliant, non-compliant)"292    },293    "Stakeholder_Engagement": {294        "stakeholder_inclusion": "string (inclusive, partially inclusive, exclusive)",295        "feedback_mechanism": "boolean",296        "stakeholder_satisfaction": "string (high, medium, low)"297    },298    "Risk_Management": {299        "risk_identification": "boolean",300        "risk_mitigation_strategies": "array of strings",301        "risk_monitoring": "boolean"302    },303 304    # Robustness-related schemas305    "System_Reliability": {306        "uptime_percentage": "number (0-100)",307        "system_resilience": "string (high, medium, low)",308        "redundancy_measures": "boolean"309    },310    "Quality_Assurance": {311        "quality_standards": "array of strings",312        "testing_frequency": "string (frequent, occasional, rare)",313        "quality_assurance_compliance": "string (compliant, partially compliant, non-compliant)"314    },315    "Stress_Testing": {316        "stress_test_pass_rate": "number (0-100)",317        "identified_weaknesses": "array of strings",318        "improvement_actions": "array of strings"319    },320    "Fail_Safe_Procedures": {321        "procedures_defined": "boolean",322        "execution_frequency": "string (regular, occasional, never)",323        "effectiveness": "string (effective, partially effective, ineffective)"324    },325 326    # Sustainability-related schemas327    "Renewable_Resources": {328        "resource_usage": "string (high, moderate, low)",329        "renewable_resource_percentage": "number (0-100)",330        "sustainability_goals": "boolean"331    },332    "Waste_Reduction": {333        "waste_management_practices": "string (effective, average, poor)",334        "reduction_rate": "number (0-100)",335        "recycling_initiatives": "boolean"336    },337    "Energy_Efficiency": {338        "energy_consumption": "string (high, moderate, low)",339        "energy_saving_measures": "array of strings",340        "energy_audit": "boolean"341    },342    "Sustainable_Practices": {343        "practice_adoption": "string (widespread, partial, none)",344        "sustainability_training": "boolean",345        "sustainability_impact": "string (high, medium, low)"346    }347}348 349 350 351