File size: 4,440 Bytes
e78a117
4d1bb75
e78a117
4d1bb75
 
e78a117
4d1bb75
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
e78a117
4d1bb75
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
---
title: ESG_Intelligence_Platform
app_file: app.py
sdk: gradio
sdk_version: 6.0.2
---
# 🌍 ESG Intelligence Platform

Advanced Multi-Label ESG Text Classification with Visual Analytics

![ESG Platform](https://img.shields.io/badge/ESG-Intelligence-22c55e?style=for-the-badge)
![Python](https://img.shields.io/badge/Python-3.9+-3776AB?style=for-the-badge&logo=python)
![Gradio](https://img.shields.io/badge/Gradio-4.0+-FF6F00?style=for-the-badge)

## ✨ Features

### πŸ” Single Text Analysis
- **Real-time ESG classification** with confidence scores
- **Visual radar chart** showing ESG profile
- **Keyword highlighting** to explain predictions
- **Interactive examples** for learning

### πŸ“ Batch Processing
- Upload **CSV or TXT files** for bulk analysis
- **Aggregate statistics** and visualizations
- **Export results** to CSV format
- **Trend analysis** across documents

### πŸ“Š Visual Analytics
- **ESG Radar Charts** - Visualize multi-dimensional ESG profiles
- **Confidence Bars** - See per-category certainty
- **Distribution Pie Charts** - Batch analysis summaries
- **Score Trend Lines** - Track patterns across documents

## πŸš€ Quick Start

### Installation

```bash
# Clone or navigate to the app directory
cd esg_app

# Install dependencies
pip install -r requirements.txt

# Run the application
python app.py
```

### Access the App

Once running, open your browser to:
- Local: `http://localhost:7860`
- Public (if share=True): Check terminal for URL

## πŸ“– Usage Guide

### Single Text Analysis

1. **Enter text** in the input box (or select a sample)
2. Click **"πŸ” Analyze Text"**
3. View results:
   - **Prediction pills** showing detected categories
   - **ESG Radar** showing dimensional scores
   - **Confidence bars** with thresholds
   - **Highlighted keywords** explaining the classification

### Batch Analysis

1. **Upload a file**:
   - **CSV**: First column should contain text
   - **TXT**: Separate documents with blank lines
2. Click **"πŸ“Š Analyze Batch"**
3. View aggregate results and export to CSV

## 🏷️ ESG Categories

| Category | Icon | Description |
|----------|------|-------------|
| **Environmental (E)** | 🌿 | Climate, emissions, energy, waste, biodiversity |
| **Social (S)** | πŸ‘₯ | Labor practices, diversity, health & safety, community |
| **Governance (G)** | βš–οΈ | Board structure, ethics, transparency, compliance |
| **Non-ESG** | πŸ“„ | General business content without ESG relevance |

## πŸ”§ Model Architecture

```
Input Text
    ↓
Qwen3-Embedding-8B (4096-dim)
    ↓
StandardScaler
    ↓
Logistic Regression Ensemble (per-class)
    ↓
Threshold Optimization
    ↓
Multi-Label Predictions
```

### Key Technical Details

- **Embedding Model**: Qwen3-Embedding-8B (4096 dimensions)
- **Classification**: Logistic Regression with balanced class weights
- **Cross-Validation**: 5-fold MultilabelStratifiedKFold
- **Threshold Optimization**: Per-class + joint macro-F1 optimization
- **Ensemble**: 3-seed averaging for robustness

## πŸ“ˆ Performance

| Metric | Score |
|--------|-------|
| **Macro F1** | 0.82+ |
| Environmental F1 | 0.78 |
| Social F1 | 0.85 |
| Governance F1 | 0.79 |
| Non-ESG F1 | 0.84 |

## 🎨 Customization

### Modify Thresholds

Edit `app.py` or `model.py`:

```python
CONFIG.thresholds = {
    'E': 0.35,    # Lower = more Environmental predictions
    'S': 0.45,    # Balanced
    'G': 0.40,    # Balanced
    'non_ESG': 0.50
}
```

### Add Keywords

Extend the keyword lists in `ESGConfig`:

```python
CONFIG.keywords['E'].extend(['sustainability', 'climate action'])
```

### Custom Styling

Modify `THEME_CSS` in `app.py` for visual customization.

## πŸ“ Project Structure

```
esg_app/
β”œβ”€β”€ app.py              # Main Gradio application
β”œβ”€β”€ model.py            # Model inference module
β”œβ”€β”€ requirements.txt    # Python dependencies
β”œβ”€β”€ README.md           # This file
└── models/             # Saved model weights (optional)
    β”œβ”€β”€ scaler.joblib
    β”œβ”€β”€ lr_E.joblib
    β”œβ”€β”€ lr_S.joblib
    β”œβ”€β”€ lr_G.joblib
    └── lr_non_ESG.joblib
```

## 🀝 Contributing

1. Fork the repository
2. Create a feature branch
3. Make your changes
4. Submit a pull request

## πŸ“œ License

MIT License - Feel free to use and modify!

---

<div align="center">
  
**Built with ❀️ for ESG Analysis**

🌿 Environmental | πŸ‘₯ Social | βš–οΈ Governance

</div>