77class CropperV1 (Document ):
88 """Cropper v1 prediction results."""
99
10- cropping : List [PositionField ]
11- """List of all detected cropped elements in the image"""
10+ cropping : List [PositionField ] = []
11+ """List of documents found in the image. """
1212
1313 def __init__ (
1414 self ,
15- api_prediction : TypeApiPrediction ,
15+ api_prediction = None ,
1616 input_source = None ,
1717 page_n : Optional [int ] = None ,
1818 ):
1919 """
20- Custom document object .
20+ Cropper v1 prediction results .
2121
22- :param document_type: Document type
2322 :param api_prediction: Raw prediction from HTTP response
2423 :param input_source: Input object
2524 :param page_n: Page number for multi pages pdf input
@@ -35,27 +34,33 @@ def __init__(
3534 def _build_from_api_prediction (
3635 self , api_prediction : TypeApiPrediction , page_n : Optional [int ] = None
3736 ) -> None :
38- """Build the document from an API response JSON."""
39- self . cropping = []
37+ """
38+ Build the object from the prediction API JSON.
4039
41- # cropping is only present on pages
40+ :param api_prediction: Raw prediction from HTTP response
41+ :param page_n: Page number
42+ """
4243 if page_n is None :
4344 return
4445
45- for crop in api_prediction ["cropping" ]:
46- self .cropping .append (PositionField (prediction = crop , page_id = page_n ))
46+ self .cropping = [
47+ PositionField (prediction , page_id = page_n )
48+ for prediction in api_prediction ["cropping" ]
49+ ]
4750
48- def _checklist (self ) -> None :
49- pass
50-
51- def __str__ (self ):
52- cropping = "\n " .join ([str (crop ) for crop in self .cropping ])
51+ def __str__ (self ) -> str :
52+ cropping = f"\n { ' ' * 18 } " .join (
53+ [str (item ) for item in self .cropping ],
54+ )
5355 return clean_out_string (
54- "----- Cropper Data ----- \n "
55- f"Filename: { self . filename or '' } \n "
56- f"Cropping: { cropping } \n "
57- "------------------------ "
56+ "Cropper V1 Prediction \n "
57+ "===================== \n "
58+ f":Filename: { self . filename or '' } \n "
59+ f":Document Cropper: { cropping } \n "
5860 )
5961
6062
61- TypeCropperV1 = TypeVar ("TypeCropperV1" , bound = CropperV1 )
63+ TypeCropperV1 = TypeVar (
64+ "TypeCropperV1" ,
65+ bound = CropperV1 ,
66+ )
0 commit comments