@@ -193,7 +193,7 @@ def extract_from_price_tag(image: Image.Image) -> Label:
193193 :param image: the input Pillow image
194194 :return: the extracted information as a dictionary
195195 """
196-
196+ client = common_google . get_genai_client ()
197197 # Gemini model max payload size is 20MB
198198 # To prevent the payload from being too large, we resize the images
199199 max_size = 1024
@@ -209,12 +209,13 @@ def extract_from_price_tag(image: Image.Image) -> Label:
209209 "I expect a single JSON in your reply, no more, no less. "
210210 "If you cannot decode an attribute, set it to an empty string."
211211 )
212- response = common_google .gemini_model .generate_content (
213- [
212+ response = client .models .generate_content (
213+ model = common_google .GEMINI_MODEL_VERSION ,
214+ contents = [
214215 prompt ,
215216 image ,
216217 ],
217- generation_config = common_google .get_generation_config (Label ),
218+ config = common_google .get_generation_config (Label ),
218219 )
219220 return json .loads (response .text )
220221
@@ -249,9 +250,11 @@ def extract_from_price_tags(images: Image.Image) -> Labels:
249250 f"I expect a list of { len (image_list )} labels in your reply, no more, no less. "
250251 "If you cannot decode an attribute, set it to an empty string"
251252 )
252- response = common_google .gemini_model .generate_content (
253- [prompt ] + image_list ,
254- generation_config = common_google .get_generation_config (Labels ),
253+ client = common_google .get_genai_client ()
254+ response = client .models .generate_content (
255+ model = common_google .GEMINI_MODEL_VERSION ,
256+ contents = [prompt ] + image_list ,
257+ config = common_google .get_generation_config (Labels ),
255258 )
256259 return json .loads (response .text )
257260
@@ -267,12 +270,14 @@ def extract_from_receipt(image: Image.Image) -> Receipt:
267270 image .thumbnail ((max_size , max_size ))
268271
269272 prompt = "Extract all relevent information, use empty strings for unknown values."
270- response = common_google .gemini_model .generate_content (
271- [
273+ client = common_google .get_genai_client ()
274+ response = client .models .generate_content (
275+ model = common_google .GEMINI_MODEL_VERSION ,
276+ contents = [
272277 prompt ,
273278 image ,
274279 ],
275- generation_config = common_google .get_generation_config (Receipt ),
280+ config = common_google .get_generation_config (Receipt ),
276281 )
277282 return json .loads (response .text )
278283
0 commit comments