mirror of
https://github.com/infiniflow/ragflow.git
synced 2025-12-08 20:42:30 +08:00
Refactor:Improve BytesIO usage for GeminiCV (#10042)
### What problem does this PR solve? Improve BytesIO usage for GeminiCV ### Type of change - [x] Refactoring
This commit is contained in:
@ -521,7 +521,8 @@ class GeminiCV(Base):
|
|||||||
else "Please describe the content of this picture, like where, when, who, what happen. If it has number data, please extract them out."
|
else "Please describe the content of this picture, like where, when, who, what happen. If it has number data, please extract them out."
|
||||||
)
|
)
|
||||||
b64 = self.image2base64(image)
|
b64 = self.image2base64(image)
|
||||||
img = open(BytesIO(base64.b64decode(b64)))
|
with BytesIO(base64.b64decode(b64)) as bio:
|
||||||
|
img = open(bio)
|
||||||
input = [prompt, img]
|
input = [prompt, img]
|
||||||
res = self.model.generate_content(input)
|
res = self.model.generate_content(input)
|
||||||
img.close()
|
img.close()
|
||||||
@ -532,11 +533,10 @@ class GeminiCV(Base):
|
|||||||
|
|
||||||
b64 = self.image2base64(image)
|
b64 = self.image2base64(image)
|
||||||
vision_prompt = prompt if prompt else vision_llm_describe_prompt()
|
vision_prompt = prompt if prompt else vision_llm_describe_prompt()
|
||||||
img = open(BytesIO(base64.b64decode(b64)))
|
with BytesIO(base64.b64decode(b64)) as bio:
|
||||||
|
img = open(bio)
|
||||||
input = [vision_prompt, img]
|
input = [vision_prompt, img]
|
||||||
res = self.model.generate_content(
|
res = self.model.generate_content(input)
|
||||||
input,
|
|
||||||
)
|
|
||||||
img.close()
|
img.close()
|
||||||
return res.text, res.usage_metadata.total_token_count
|
return res.text, res.usage_metadata.total_token_count
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user