File size: 2,674 Bytes
cb2ce22
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
---
title: Cfm Topic Classifier
emoji: 😻
colorFrom: green
colorTo: green
sdk: gradio
sdk_version: 6.2.0
app_file: app.py
pinned: false
short_description: ModernBERT encoder model fine-tuned on CFM topics
---

# 💧 WASH CFM Topic Classifier

A Gradio web application for classifying WASH (Water, Sanitation, and Hygiene) feedback into relevant topic categories using a fine-tuned ModernBERT model.

## Features

- **Topic Classification**: Automatically classifies WASH feedback into relevant topic categories
- **ModernBERT Integration**: Uses a fine-tuned ModernBERT-large model for accurate classification
- **Multi-Device Support**: Automatically detects and utilizes the best available device:
  - Apple Silicon (MPS)
  - NVIDIA GPU (CUDA)
  - CPU fallback
- **Top-K Predictions**: Shows the top 2 most probable topics with confidence scores
- **Interactive Interface**: User-friendly Gradio interface with real-time classification
- **Input Validation**: Validates input and provides helpful error messages

## Installation

1. Clone or download this repository
2. Install the required dependencies:

```bash
pip install -r requirements.txt
```

3. Ensure the model files are available in the `./wash_cfm_classifier/` directory

## Usage

1. Run the application:

```bash
python app.py
```

2. Open your web browser and navigate to `http://localhost:7860`

3. Enter WASH feedback text in the input box (e.g., "The water pump in our area has been broken for 3 days...")

4. Click "Submit" to get topic predictions with confidence scores

5. Use the "Clear" button to reset the interface

## Requirements

- Python 3.7+
- torch>=2.0.0
- transformers>=4.30.0  
- gradio>=4.0.0

## Technical Details

- **Model**: Fine-tuned ModernBERT-large for sequence classification
- **Framework**: Gradio for web interface
- **Device Support**: Automatic device detection (MPS/CUDA/CPU)
- **Caching**: LRU cache for model loading to improve performance
- **Output Format**: HTML-formatted results with confidence percentages

## Example Input/Output

**Input**: "The water pump in our area has been broken for 3 days and we need access to clean water"

**Output**: 
1. **Water Supply** - Confidence: 95.2%
2. **Infrastructure** - Confidence: 87.1%

## Error Handling

- Validates empty or whitespace-only input
- Handles missing model files gracefully
- Provides detailed error messages for troubleshooting

## Configuration

- **Server Address**: `0.0.0.0` (all interfaces)
- **Port**: `7860`
- **Model Path**: `./wash_cfm_classifier/`
- **Top-K Predictions**: `2`

## License

UNICEF WASH Cluster CFM System

---

*Powered by ModernBERT-large | UNICEF WASH Cluster CFM System*