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www.python.org/downloads/)
|
| 7 |
+
[](https://fastapi.tiangolo.com)
|
| 8 |
+
[](LICENSE)
|
| 9 |
+
|
| 10 |
+
## What it does
|
| 11 |
+
|
| 12 |
+
Solves the most common CAPTCHA types by combining local AI models in a layered pipeline:
|
| 13 |
+
|
| 14 |
+
| Type | How solved | Realistic accuracy |
|
| 15 |
+
|---|---|---|
|
| 16 |
+
| **Math** (`3 + 5 = ?`) | regex + small LLM | **95%+** |
|
| 17 |
+
| **Audio** (reCAPTCHA audio) | local Whisper | **70-85%** |
|
| 18 |
+
| **Text OCR** (distorted letters) | Florence-2 + LLM cleanup | **65-80%** |
|
| 19 |
+
| **Image grid** (reCAPTCHA v2) | Moondream2 / Qwen2-VL | **30-55%** |
|
| 20 |
+
|
| 21 |
+
## Architecture
|
| 22 |
+
|
| 23 |
+
```
|
| 24 |
+
┌──────────────────┐
|
| 25 |
+
POST /solve ────────▶│ FastAPI server │
|
| 26 |
+
(base64 captcha) │ + router │
|
| 27 |
+
└────────┬─────────┘
|
| 28 |
+
│
|
| 29 |
+
┌──────────────────┼──────────────────┐
|
| 30 |
+
│ │ │
|
| 31 |
+
┌─────▼─────┐ ┌──────▼──────┐ ┌───────▼──────┐
|
| 32 |
+
│ Solvers │ │ Solvers │ │ Solvers │
|
| 33 |
+
│ math │ │ audio │ │ text_ocr │
|
| 34 |
+
│ regex │ │ whisper │ │ florence-2 │
|
| 35 |
+
│ + LLM │ │ + cleanup │ │ + LLM │
|
| 36 |
+
└─────┬─────┘ └──────┬──────┘ └───────┬──────┘
|
| 37 |
+
│ │ │
|
| 38 |
+
└──────────────────┼──────────────────┘
|
| 39 |
+
│
|
| 40 |
+
┌────────▼─────────┐
|
| 41 |
+
│ Engines │
|
| 42 |
+
│ faster-whisper │
|
| 43 |
+
│ HF transformers │
|
| 44 |
+
│ ollama (opt.) │
|
| 45 |
+
└──────────────────┘
|
| 46 |
+
```
|
| 47 |
+
|
| 48 |
+
## Quick start
|
| 49 |
+
|
| 50 |
+
### Option A: pip (simplest)
|
| 51 |
+
|
| 52 |
+
```bash
|
| 53 |
+
git clone https://github.com/wo312092-creator/captcha-solver-api
|
| 54 |
+
cd captcha-solver-api
|
| 55 |
+
pip install -r requirements.txt
|
| 56 |
+
python -m captcha_solver.main
|
| 57 |
+
```
|
| 58 |
+
|
| 59 |
+
Server starts on `http://localhost:8765`.
|
| 60 |
+
|
| 61 |
+
### Option B: Docker (recommended for selling/hosting)
|
| 62 |
+
|
| 63 |
+
```bash
|
| 64 |
+
docker-compose up -d
|
| 65 |
+
```
|
| 66 |
+
|
| 67 |
+
That's it. First request downloads models (~500 MB for default config).
|
| 68 |
+
|
| 69 |
+
## What works without any model download
|
| 70 |
+
|
| 71 |
+
If your Hugging Face token has expired, or you're offline, the math
|
| 72 |
+
solver still works **if you pass the captcha text as the `hint` field**.
|
| 73 |
+
The opportunity-hunter-v2 integration can extract the captcha text
|
| 74 |
+
from the page DOM and pass it as hint:
|
| 75 |
+
|
| 76 |
+
```json
|
| 77 |
+
{
|
| 78 |
+
"type": "math",
|
| 79 |
+
"hint": "3 + 5 = ?"
|
| 80 |
+
}
|
| 81 |
+
```
|
| 82 |
+
|
| 83 |
+
Response: `{"answer": "8", "success": true, ...}`
|
| 84 |
+
|
| 85 |
+
For **image input without a model**, install Tesseract OCR:
|
| 86 |
+
1. `pip install pytesseract` (already in requirements.txt)
|
| 87 |
+
2. Windows: download installer from https://github.com/UB-Mannheim/tesseract/wiki
|
| 88 |
+
3. Linux: `apt install tesseract-ocr`
|
| 89 |
+
4. macOS: `brew install tesseract`
|
| 90 |
+
|
| 91 |
+
The math solver will fall back to Tesseract if Florence-2 can't load.
|
| 92 |
+
This gives you a fully working math captcha solver with zero model
|
| 93 |
+
downloads.
|
| 94 |
+
|
| 95 |
+
## API
|
| 96 |
+
|
| 97 |
+
### `POST /solve`
|
| 98 |
+
|
| 99 |
+
```json
|
| 100 |
+
{
|
| 101 |
+
"type": "math",
|
| 102 |
+
"image_base64": "iVBORw0KGgo...",
|
| 103 |
+
"audio_base64": null,
|
| 104 |
+
"timeout": 30
|
| 105 |
+
}
|
| 106 |
+
```
|
| 107 |
+
|
| 108 |
+
Or with audio:
|
| 109 |
+
|
| 110 |
+
```json
|
| 111 |
+
{
|
| 112 |
+
"type": "audio",
|
| 113 |
+
"image_base64": null,
|
| 114 |
+
"audio_base64": "SUQz...",
|
| 115 |
+
"timeout": 30
|
| 116 |
+
}
|
| 117 |
+
```
|
| 118 |
+
|
| 119 |
+
Response:
|
| 120 |
+
|
| 121 |
+
```json
|
| 122 |
+
{
|
| 123 |
+
"success": true,
|
| 124 |
+
"answer": "8",
|
| 125 |
+
"confidence": 0.95,
|
| 126 |
+
"solver": "math.regex",
|
| 127 |
+
"elapsed_ms": 12,
|
| 128 |
+
"cache_hit": false
|
| 129 |
+
}
|
| 130 |
+
```
|
| 131 |
+
|
| 132 |
+
### `GET /health`
|
| 133 |
+
|
| 134 |
+
```json
|
| 135 |
+
{
|
| 136 |
+
"status": "ok",
|
| 137 |
+
"engines": {
|
| 138 |
+
"whisper": "loaded",
|
| 139 |
+
"florence2": "loaded",
|
| 140 |
+
"moondream2": "loaded",
|
| 141 |
+
"ollama": "disabled"
|
| 142 |
+
},
|
| 143 |
+
"version": "0.1.0"
|
| 144 |
+
}
|
| 145 |
+
```
|
| 146 |
+
|
| 147 |
+
### `GET /stats`
|
| 148 |
+
|
| 149 |
+
```json
|
| 150 |
+
{
|
| 151 |
+
"total_requests": 1247,
|
| 152 |
+
"by_type": {"math": 800, "audio": 300, "image_grid": 147},
|
| 153 |
+
"by_solver": {"math.regex": 780, "math.llm": 18, "audio.whisper": 245, ...},
|
| 154 |
+
"success_rate": 0.82,
|
| 155 |
+
"avg_elapsed_ms": 423
|
| 156 |
+
}
|
| 157 |
+
```
|
| 158 |
+
|
| 159 |
+
### `GET /models`
|
| 160 |
+
|
| 161 |
+
Lists loaded models + download URLs for optional upgrades.
|
| 162 |
+
|
| 163 |
+
## Honest accuracy
|
| 164 |
+
|
| 165 |
+
This API uses **real, local, free AI models**. It is not magic. Realistic accuracy:
|
| 166 |
+
|
| 167 |
+
- ✓ Math captchas: 95%+ (very reliable)
|
| 168 |
+
- ✓ Audio reCAPTCHA: 70-85% (Google fights back; this will degrade)
|
| 169 |
+
- ⚠️ Text OCR: 65-80% (depends on distortion)
|
| 170 |
+
- ⚠️ Image grid: 30-55% (reliably beats ~half of them)
|
| 171 |
+
- ✗ Invisible CAPTCHAs (v3, Turnstile): NOT solvable by AI (use behavior mimicry)
|
| 172 |
+
- ✗ hCaptcha enterprise: limited (use residential proxies)
|
| 173 |
+
|
| 174 |
+
**The honest truth**: no AI service beats every CAPTCHA. The trick is layered fallbacks: math → audio → image → manual. This API gives you 4 free layers.
|
| 175 |
+
|
| 176 |
+
## Use in your own automation
|
| 177 |
+
|
| 178 |
+
```python
|
| 179 |
+
import requests
|
| 180 |
+
|
| 181 |
+
# Solve a math captcha
|
| 182 |
+
r = requests.post("http://localhost:8765/solve", json={
|
| 183 |
+
"type": "math",
|
| 184 |
+
"image_base64": encode(open("captcha.png", "rb").read())
|
| 185 |
+
})
|
| 186 |
+
print(r.json()["answer"]) # "8"
|
| 187 |
+
```
|
| 188 |
+
|
| 189 |
+
```python
|
| 190 |
+
# Solve an audio captcha (reCAPTCHA v2)
|
| 191 |
+
r = requests.post("http://localhost:8765/solve", json={
|
| 192 |
+
"type": "audio",
|
| 193 |
+
"audio_base64": encode(open("recaptcha.mp3", "rb").read())
|
| 194 |
+
})
|
| 195 |
+
print(r.json()["answer"]) # "7 4 2 9 8"
|
| 196 |
+
```
|
| 197 |
+
|
| 198 |
+
## Integration with opportunity-hunter-v2
|
| 199 |
+
|
| 200 |
+
`opportunity-hunter-v2` should call this service when it hits a CAPTCHA:
|
| 201 |
+
|
| 202 |
+
```python
|
| 203 |
+
import requests
|
| 204 |
+
SOLVER = "http://localhost:8765/solve"
|
| 205 |
+
|
| 206 |
+
def solve_captcha(image_bytes, hint=None):
|
| 207 |
+
return requests.post(SOLVER, json={
|
| 208 |
+
"type": hint or "auto",
|
| 209 |
+
"image_base64": base64.b64encode(image_bytes).decode()
|
| 210 |
+
}, timeout=30).json()
|
| 211 |
+
```
|
| 212 |
+
|
| 213 |
+
## Models used
|
| 214 |
+
|
| 215 |
+
All run locally. No cloud. No API keys.
|
| 216 |
+
|
| 217 |
+
| Model | Size | Purpose | First-time download |
|
| 218 |
+
|---|---|---|---|
|
| 219 |
+
| faster-whisper (tiny) | 75 MB | Audio transcription | 75 MB |
|
| 220 |
+
| Florence-2-base | 1.2 GB | OCR + detection | 1.2 GB |
|
| 221 |
+
| Moondream2 | 1.7 GB | Image grid VQA | 1.7 GB |
|
| 222 |
+
| Qwen2.5-1.5B-Instruct | 1.5 GB | Text reasoning fallback | 1.5 GB |
|
| 223 |
+
|
| 224 |
+
**Optional upgrade (better results, requires ollama):**
|
| 225 |
+
|
| 226 |
+
| Model | Size | Why upgrade |
|
| 227 |
+
|---|---|---|
|
| 228 |
+
| Qwen2-VL 7B (via ollama) | 4.5 GB | Best image grid accuracy |
|
| 229 |
+
| Whisper large-v3 | 3 GB | Best audio accuracy |
|
| 230 |
+
|
| 231 |
+
## Client library (Python)
|
| 232 |
+
|
| 233 |
+
`captcha_client.py` is a one-file wrapper included in this repo:
|
| 234 |
+
|
| 235 |
+
```python
|
| 236 |
+
from captcha_client import solve_captcha, is_available
|
| 237 |
+
|
| 238 |
+
if not is_available():
|
| 239 |
+
raise SystemExit("start the solver: python scripts/start_server.py")
|
| 240 |
+
|
| 241 |
+
# Most reliable: text hint (e.g. "3 + 5 = ?")
|
| 242 |
+
answer = solve_captcha(hint="3 + 5 = ?") # → "8"
|
| 243 |
+
|
| 244 |
+
# Or from a cropped captcha image
|
| 245 |
+
answer = solve_captcha(image="captcha.png") # → "8"
|
| 246 |
+
|
| 247 |
+
# Or raw image bytes
|
| 248 |
+
answer = solve_captcha(image=png_bytes) # → "8"
|
| 249 |
+
```
|
| 250 |
+
|
| 251 |
+
Set `CAPTCHA_SOLVER_URL` env var to override the default `http://localhost:8765`.
|
| 252 |
+
|
| 253 |
+
## End-to-end test (Windows)
|
| 254 |
+
|
| 255 |
+
```powershell
|
| 256 |
+
# 1. Start the server (auto-relaunches on crash)
|
| 257 |
+
python D:\opencode\captcha-solver-api\scripts\start_server.py
|
| 258 |
+
|
| 259 |
+
# 2. In another shell
|
| 260 |
+
python D:\opencode\captcha-solver-api\tests\test_e2e.py
|
| 261 |
+
```
|
| 262 |
+
|
| 263 |
+
## Learning system
|
| 264 |
+
|
| 265 |
+
Every solve attempt is recorded in a local SQLite database (`data/learning.db`). The system tracks:
|
| 266 |
+
|
| 267 |
+
| Metric | Purpose |
|
| 268 |
+
|---|---|
|
| 269 |
+
| Per-solver accuracy | Which solver works best for each captcha type |
|
| 270 |
+
| Failure patterns | Common mistakes by solver |
|
| 271 |
+
| Optimization history | What was changed and whether it improved accuracy |
|
| 272 |
+
|
| 273 |
+
**Hourly learning cycle** (via GitHub Action `.github/workflows/learn.yml`):
|
| 274 |
+
|
| 275 |
+
```yaml
|
| 276 |
+
# Runs every hour, simulates captcha solves across all solvers,
|
| 277 |
+
# records results, analyzes failures, and suggests optimizations.
|
| 278 |
+
```
|
| 279 |
+
|
| 280 |
+
The workflow:
|
| 281 |
+
1. Restores the previous learning DB from cache
|
| 282 |
+
2. Runs 30 simulated solves across all solvers
|
| 283 |
+
3. Records every attempt with latency, confidence, and correctness
|
| 284 |
+
4. Runs `Trainer.optimize()` to identify underperforming solvers
|
| 285 |
+
5. Uploads the updated DB as a 90-day artifact
|
| 286 |
+
6. Publishes an accuracy trend report in the Action summary
|
| 287 |
+
|
| 288 |
+
**Query stats at runtime** via the API (when server is running):
|
| 289 |
+
|
| 290 |
+
```bash
|
| 291 |
+
curl http://localhost:8765/stats
|
| 292 |
+
```
|
| 293 |
+
|
| 294 |
+
Returns solver rankings, recent failures, and overall accuracy trend.
|
| 295 |
+
|
| 296 |
+
## License
|
| 297 |
+
|
| 298 |
+
MIT. Use it. Sell it. Modify it. Just don't blame us when Google blocks your IP.
|