| import plotly.graph_objects as go | |
| def compute_esg_keyword_distribution(text): | |
| text = text.lower() | |
| environmental_keywords = ["emission", "carbon", "climate", "energy", "waste"] | |
| social_keywords = ["diversity", "employee", "community", "health", "safety"] | |
| governance_keywords = ["board", "compliance", "audit", "ethics", "policy"] | |
| e_count = sum(text.count(word) for word in environmental_keywords) | |
| s_count = sum(text.count(word) for word in social_keywords) | |
| g_count = sum(text.count(word) for word in governance_keywords) | |
| total = max(e_count + s_count + g_count, 1) | |
| return { | |
| "Environmental": e_count, | |
| "Social": s_count, | |
| "Governance": g_count, | |
| "Total": total | |
| } | |
| def generate_esg_statistics_chart(text): | |
| stats = compute_esg_keyword_distribution(text) | |
| fig = go.Figure(data=[ | |
| go.Pie( | |
| labels=["Environmental", "Social", "Governance"], | |
| values=[ | |
| stats["Environmental"], | |
| stats["Social"], | |
| stats["Governance"] | |
| ], | |
| hole=0.5 | |
| ) | |
| ]) | |
| fig.update_layout( | |
| title="ESG Keyword Distribution (Donut Chart)", | |
| template="plotly_dark" | |
| ) | |
| return fig | |