Skip to content

Commit 21c7cdc

Browse files
committed
captcha: Remove CLI from predict.py
1 parent 591a521 commit 21c7cdc

1 file changed

Lines changed: 2 additions & 25 deletions

File tree

captcha/predict.py

Lines changed: 2 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"""
33
Predict the 6-character text of an Assam tenders captcha.
44
5-
Library usage:
5+
Library API:
66
from predict import predict, predict_with_confidence
77
88
text = predict("samples/captcha_0001.png")
@@ -11,17 +11,14 @@
1111
text = predict(pil_image) # PIL.Image
1212
text, conf = predict_with_confidence(image) # conf is list[float], one per character
1313
14-
CLI usage:
15-
./predict.py samples/captcha_0001.png
14+
The CLI lives in `manage.py predict`.
1615
"""
1716

1817
from __future__ import annotations
1918

20-
import argparse
2119
import base64
2220
import binascii
2321
import io
24-
import sys
2522
from functools import cache
2623
from pathlib import Path
2724

@@ -121,23 +118,3 @@ def predict(image: ImageInput, model_path: Path = DEFAULT_MODEL_PATH) -> str:
121118
def predict_with_confidence(image: ImageInput, model_path: Path = DEFAULT_MODEL_PATH) -> tuple[str, list[float]]:
122119
"""Return (prediction, per-character confidence) for the captcha image."""
123120
return _infer(_to_rgb(image), model_path)
124-
125-
126-
def main() -> int:
127-
parser = argparse.ArgumentParser(description=__doc__)
128-
parser.add_argument("image", help="Path to a PNG captcha")
129-
parser.add_argument("--model", type=Path, default=DEFAULT_MODEL_PATH)
130-
parser.add_argument("--confidence", action="store_true", help="Also print per-char confidence")
131-
args = parser.parse_args()
132-
133-
if args.confidence:
134-
text, conf = predict_with_confidence(args.image, args.model)
135-
print(text)
136-
print(" ".join(f"{c}={p:.2f}" for c, p in zip(text, conf, strict=False)))
137-
else:
138-
print(predict(args.image, args.model))
139-
return 0
140-
141-
142-
if __name__ == "__main__":
143-
sys.exit(main())

0 commit comments

Comments
 (0)