@@ -503,3 +503,35 @@ def get_webhook_details(self, webhook_name: str) -> dict:
503503 err ["status_code" ] = response .status_code
504504 raise LLMWhispererClientException (err )
505505 return json .loads (response .text )
506+
507+ def get_highlight_rect (
508+ self ,
509+ line_metadata : list [int ],
510+ target_width : int ,
511+ target_height : int ,
512+ ) -> tuple [int , int , int , int , int ]:
513+ """
514+ Given the line metadata and the line number, this function returns the bounding box of the line
515+ in the format (page,x1,y1,x2,y2)
516+
517+ Args:
518+ line_metadata (list[int]): The line metadata returned by the LLMWhisperer API.
519+ line_no (int): The line number for which the bounding box is required.
520+ target_width (int): The width of your target image/page in UI.
521+ target_height (int): The height of your target image/page in UI.
522+
523+ Returns:
524+ tuple: The bounding box of the line in the format (page,x1,y1,x2,y2)
525+ """
526+
527+ page = line_metadata [0 ]
528+ x1 = 0
529+ y1 = line_metadata [1 ] - line_metadata [2 ]
530+ x2 = target_width
531+ y2 = line_metadata [1 ]
532+ original_height = line_metadata [3 ]
533+
534+ y1 = int ((float (y1 ) / float (original_height )) * float (target_height ))
535+ y2 = int ((float (y2 ) / float (original_height )) * float (target_height ))
536+
537+ return (page , x1 , y1 , x2 , y2 )
0 commit comments