File size: 4,644 Bytes
900df0b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
244
245
246
247
248
249
250
251
252
# OmniFile AI Processor - API Documentation

## Base URL

```
http://localhost:5001
```

Interactive docs available at:
- Swagger UI: `http://localhost:5001/docs`
- ReDoc: `http://localhost:5001/redoc`

---

## Endpoints

### 1. Health Check

**GET** `/health`

Response:
```json
{
  "status": "healthy",
  "engines": [...],
  "uptime": 1234567890.123
}
```

### 2. Available Engines

**GET** `/engines`

Response:
```json
{
  "engines": [
    {"name": "EasyOCR", "available": true, "enabled": true, "loaded": false},
    {"name": "TrOCR", "available": true, "enabled": true, "loaded": false},
    {"name": "Tesseract", "available": true, "enabled": true, "loaded": true},
    {"name": "PaddleOCR", "available": false, "enabled": false, "loaded": false}
  ]
}
```

### 3. System Configuration

**GET** `/api/config`

Response:
```json
{
  "supported_languages": ["en", "ar", "de"],
  "enable_summarization": true,
  "enable_translation": true,
  "dark_mode": true,
  "ocr_engines": ["trocr", "easyocr", "tesseract", "paddleocr"]
}
```

### 4. OCR Processing

**POST** `/api/ocr/process`

Content-Type: `multipart/form-data`

Parameters:
| Parameter | Type | Required | Default | Description |
|-----------|------|----------|---------|-------------|
| file | File | Yes | - | Image or PDF file |
| languages | string | No | "en,ar" | Comma-separated language codes |
| engines | string | No | "easyocr,trocr" | Comma-separated engine names |
| preprocess | boolean | No | true | Apply image preprocessing |

Response:
```json
{
  "success": true,
  "text": "Extracted text here...",
  "confidence": 0.95,
  "languages": ["en", "ar"],
  "engines": ["easyocr", "trocr"],
  "filename": "document.png"
}
```

### 5. Spell Correction

**POST** `/api/ocr/correct`

Content-Type: `application/json`

Request:
```json
{
  "text": "helloo world testt",
  "lang": "en"
}
```

Response:
```json
{
  "success": true,
  "original_text": "helloo world testt",
  "corrected_text": "hello world test",
  "corrections": [
    {"original": "helloo", "corrected": "hello", "position": 0},
    {"original": "testt", "corrected": "test", "position": 13}
  ],
  "total_corrections": 2
}
```

### 6. Translation

**POST** `/api/nlp/translate`

Content-Type: `application/json`

Request:
```json
{
  "text": "Hello world",
  "source_lang": "en",
  "target_lang": "ar"
}
```

Response:
```json
{
  "success": true,
  "original_text": "Hello world",
  "translated_text": "مرحبا بالعالم",
  "source_lang": "en",
  "target_lang": "ar",
  "model": "Helsinki-NLP/opus-mt"
}
```

### 7. Summarization

**POST** `/api/nlp/summarize`

Content-Type: `application/json`

Request:
```json
{
  "text": "Long text to summarize...",
  "lang": "auto",
  "max_length": 130,
  "min_length": 30
}
```

Response:
```json
{
  "success": true,
  "original_text": "Long text...",
  "summary": "Summary text...",
  "lang": "en"
}
```

### 8. OCR Evaluation (CER/WER)

**POST** `/api/evaluate`

Content-Type: `application/json`

Request:
```json
{
  "reference_text": "The correct text",
  "ocr_text": "The ocr text"
}
```

Response:
```json
{
  "success": true,
  "cer": 0.15,
  "wer": 0.2,
  "accuracy": 85.0,
  "quality_grade": "B+",
  "recommendations": []
}
```

### 9. AI Text Improvement

**POST** `/api/ai/improve`

Content-Type: `multipart/form-data`

Parameters:
| Parameter | Type | Required | Description |
|-----------|------|----------|-------------|
| text | string | Yes | Text to improve |
| language | string | No | Language code (default: "ar") |
| context | string | No | Additional context for correction |

### 10. Batch Processing

**POST** `/api/batch/process`

Content-Type: `multipart/form-data`

Parameters:
| Parameter | Type | Required | Description |
|-----------|------|----------|-------------|
| files | File[] | Yes | Multiple image/PDF files |
| languages | string | No | Comma-separated language codes |

### 11. Task Status

**GET** `/api/tasks/{task_id}`

Response:
```json
{
  "status": "completed",
  "total": 5,
  "completed": 5,
  "results": [...]
}
```

---

## Supported Languages

| Code | Language | OCR | Spell Check | Translation | Summarization |
|------|----------|-----|-------------|-------------|---------------|
| en | English | Yes | Yes | Yes | Yes (BART) |
| ar | Arabic | Yes | Yes | Yes | Yes (mBART) |
| de | German | Yes | Yes | Yes | Yes (mT5) |

## Error Codes

| Status | Description |
|--------|-------------|
| 400 | Bad Request (invalid parameters) |
| 404 | Not Found (task/resource) |
| 413 | File Too Large (max 50MB) |
| 500 | Internal Server Error |
| 503 | Service Unavailable (AI features require API key) |