File size: 4,984 Bytes
90e5963
 
2617189
 
90e5963
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
# API Documentation — Multilingual ABSA

> ⚠️ The REST API has been removed. The app is now a single Gradio interface. This doc is kept for historical reference only.

## Base URL

- Local development: `http://localhost:8000`
- Production: `https://your-railway-app.up.railway.app`

## Authentication

Currently **none**. All endpoints are publicly accessible.

## Endpoints

### POST /predict

Analyze a single review for aspect-based sentiment.

**Request Body:**
```json
{
  "text": "The food was great but the service was terrible.",
  "language": "en"
}
```

| Field | Type | Required | Description |
|-------|------|----------|-------------|
| `text` | string | Yes | Review text to analyze |
| `language` | string | No | Force language (`"en"`, `"hi"`, `"hinglish"`). Auto-detected if omitted |

**Response `200`:**

```json
{
  "text": "The food was great but the service was terrible.",
  "language": "en",
  "detected_language": "en",
  "aspects": [
    {
      "aspect": "Food",
      "sentiment": "positive",
      "confidence": 0.85,
      "start": 4,
      "end": 8
    },
    {
      "aspect": "Service",
      "sentiment": "negative",
      "confidence": 0.82,
      "start": 27,
      "end": 34
    }
  ],
  "processing_time_ms": 185.3
}
```

| Field | Type | Description |
|-------|------|-------------|
| `text` | string | Original input text |
| `language` | string | Language used (detected or forced) |
| `detected_language` | string | Auto-detected language code |
| `aspects` | array | List of extracted aspect-sentiment pairs |
| `processing_time_ms` | float | Total inference time in milliseconds |

**Aspect Object:**

| Field | Type | Description |
|-------|------|-------------|
| `aspect` | string | Extracted aspect term (title-cased) |
| `sentiment` | string | `"positive"`, `"negative"`, `"neutral"`, or `"conflict"` |
| `confidence` | float | Confidence score (0.0–1.0) |
| `start` | int | Character offset start in original text |
| `end` | int | Character offset end in original text |

**Error Responses:**

| Status | Condition |
|--------|-----------|
| 422 | Empty text, missing `text` field |
| 500 | Model inference failure |

---

### POST /batch

Upload a CSV file for batch analysis. Processed asynchronously via Celery.

**Request:** `multipart/form-data`

| Field | Type | Required | Description |
|-------|------|----------|-------------|
| `file` | file | Yes | CSV file with a `text` column (max 10,000 rows) |

**Response `200`:**

```json
{
  "job_id": "a1b2c3d4-e5f6-7890-abcd-ef1234567890",
  "status": "queued",
  "total_reviews": 4250,
  "processed": 0,
  "result_url": null
}
```

**Error Responses:**

| Status | Condition |
|--------|-----------|
| 422 | Non-CSV file, missing `text` column, >10K rows |
| 500 | Batch processing failed |

---

### GET /status/{job_id}

Poll batch job progress.

**Response `200` (processing):**

```json
{
  "job_id": "a1b2c3d4-e5f6-7890-abcd-ef1234567890",
  "status": "processing",
  "total_reviews": 4250,
  "processed": 1200,
  "result_url": null
}
```

**Response `200` (completed):**

```json
{
  "job_id": "a1b2c3d4-e5f6-7890-abcd-ef1234567890",
  "status": "completed",
  "total_reviews": 4250,
  "processed": 4250,
  "result_url": "/results/download/a1b2c3d4-e5f6-7890-abcd-ef1234567890"
}
```

**Error Responses:**

| Status | Condition |
|--------|-----------|
| 404 | Job ID not found |

---

### GET /health

System health check.

**Response `200`:**

```json
{
  "status": "ok",
  "model": "loaded",
  "db": "connected"
}
```

---

### GET /info

Get model metadata.

**Response `200`:**

```json
{
  "model_name": "xlm-roberta-base-absa",
  "version": "1.0",
  "supported_languages": "en, hi",
  "max_batch_size": "10000"
}
```

---

### GET /metrics

Prometheus metrics endpoint (auto-instrumented).

**Response `200`:** Prometheus text format metrics.

Available metrics:
- `fastapi_requests_total` (counter by method, path, status)
- `fastapi_requests_duration_seconds` (histogram)
- `fastapi_requests_inprogress` (gauge)
- Custom ABSA metrics (if implemented)

---

## Example Usage

### cURL

```bash
# Single prediction
curl -X POST http://localhost:8000/predict \
  -H "Content-Type: application/json" \
  -d '{"text": "This phone has amazing battery life but the camera is disappointing", "language": "en"}'

# Health check
curl http://localhost:8000/health

# Model info
curl http://localhost:8000/info
```

### Python

```python
import httpx

response = httpx.post(
    "http://localhost:8000/predict",
    json={"text": "This phone has amazing battery life but the camera is disappointing"}
)
print(response.json())
```

### JavaScript

```javascript
const response = await fetch('http://localhost:8000/predict', {
  method: 'POST',
  headers: { 'Content-Type': 'application/json' },
  body: JSON.stringify({
    text: 'This phone has amazing battery life but the camera is disappointing'
  })
});
const data = await response.json();
console.log(data);
```