File size: 3,264 Bytes
00d416d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
# BAYAN — API Contract Documentation

## Base URL
```
https://bayan10-bayan-api.hf.space
```

---

## GET /api/health

**Purpose:** Production health check and model status.

**Request:** No body required.

**Response:**
```json
{
  "status": "healthy",
  "mode": "hf_spaces_local",
  "models": {
    "summarization": true,
    "spelling": true,
    "grammar": true,
    "punctuation": true,
    "autocomplete": false
  },
  "supabase": {
    "configured": true
  },
  "environment": "huggingface_spaces"
}
```

> [!NOTE]
> NLP models use lazy loading. `spelling`, `grammar`, `punctuation` report `false` until first inference request triggers model loading. After first call, they report `true` for the lifetime of the process.

---

## POST /api/analyze

**Purpose:** Full NLP pipeline (Spelling → Grammar → Punctuation). Primary endpoint used by the editor.

**Request:**
```json
{
  "text": "Arabic text to analyze"
}
```

**Response:**
```json
{
  "status": "success",
  "original": "input text",
  "corrected": "fully corrected text",
  "suggestions": [
    {
      "start": 0,
      "end": 5,
      "original": "word",
      "correction": "corrected_word",
      "type": "spelling|grammar|punctuation",
      "alternatives": ["alt1", "alt2"]
    }
  ]
}
```

**Error (400):** Empty or missing text
**Error (500):** Server error

**Suggestion Types & Colors:**
| Type | Color |
|------|-------|
| `spelling` | 🔴 Red `#ef4444` |
| `grammar` | 🟡 Yellow `#eab308` |
| `punctuation` | 🟢 Green `#22c55e` |

**Max Text Length:** 5000 characters

---

## POST /api/spelling

**Purpose:** Standalone spelling correction.

**Request:**
```json
{
  "text": "Arabic text with spelling errors"
}
```

**Response:**
```json
{
  "status": "success",
  "original_text": "input text",
  "corrected_text": "corrected text"
}
```

**Error (400):** Empty text, text > 5000 chars
**Error (503):** Model unavailable

---

## POST /api/grammar

**Purpose:** Standalone grammar correction.

**Request:**
```json
{
  "text": "Arabic text with grammar errors"
}
```

**Response:**
```json
{
  "status": "success",
  "original_text": "input text",
  "corrected_text": "corrected text"
}
```

**Error (503):** Model/Gradio Space unavailable

---

## POST /api/punctuation

**Purpose:** Standalone punctuation restoration.

**Request:**
```json
{
  "text": "Arabic text without punctuation"
}
```

**Response:**
```json
{
  "status": "success",
  "original_text": "input text",
  "corrected_text": "punctuated text"
}
```

**Error (503):** Model unavailable

---

## POST /api/summarize

**Purpose:** Arabic text summarization.

**Request:**
```json
{
  "text": "Long Arabic text to summarize (min 10 chars)"
}
```

**Response:**
```json
{
  "status": "success",
  "summary": "summarized text",
  "original_length": 500,
  "summary_length": 120
}
```

**Error (400):** Text too short (< 10 chars) or too long (> 5000 chars)

---

## Error Response Schema

All endpoints return errors in this format:
```json
{
  "status": "error",
  "error": "Human-readable error message"
}
```

## Common HTTP Status Codes

| Code | Meaning |
|------|---------|
| 200 | Success |
| 400 | Bad request (missing/invalid input) |
| 500 | Internal server error |
| 503 | Model unavailable |