Spaces:
Sleeping
Sleeping
Update utils.py
Browse files
utils.py
CHANGED
@@ -1,7 +1,7 @@
|
|
1 |
-
|
|
|
2 |
|
3 |
-
|
4 |
-
genai.configure(api_key="AIzaSyAP85jSUKncrIGOAhm3Gvo-TYra_e1wmEA")
|
5 |
import os
|
6 |
import pandas as pd
|
7 |
import io
|
@@ -94,22 +94,19 @@ def analyze_pdf_images_with_gemini(pdf_bytes):
|
|
94 |
# Initialize Gemini client
|
95 |
|
96 |
images = pdf_to_images(pdf_bytes)
|
97 |
-
|
98 |
# Prepare image parts
|
99 |
contents = [question]
|
100 |
for img in images:
|
101 |
img_bytes = pil_image_to_bytes(img)
|
102 |
-
contents.append(
|
103 |
-
'mime_type': 'image/jpeg',
|
104 |
-
'data': img_bytes
|
105 |
-
})
|
106 |
-
#contents.append(genai.types.Part.from_bytes(data=img_bytes, mime_type="image/jpeg"))
|
107 |
|
108 |
# Generate content using Gemini
|
109 |
-
|
110 |
-
|
111 |
-
|
112 |
-
|
|
|
113 |
|
114 |
return response
|
115 |
|
|
|
1 |
+
from google import genai
|
2 |
+
from google.genai import types
|
3 |
|
4 |
+
#genai.configure(api_key="AIzaSyAP85jSUKncrIGOAhm3Gvo-TYra_e1wmEA")
|
|
|
5 |
import os
|
6 |
import pandas as pd
|
7 |
import io
|
|
|
94 |
# Initialize Gemini client
|
95 |
|
96 |
images = pdf_to_images(pdf_bytes)
|
97 |
+
client = genai.Client(api_key="AIzaSyAP85jSUKncrIGOAhm3Gvo-TYra_e1wmEA")
|
98 |
# Prepare image parts
|
99 |
contents = [question]
|
100 |
for img in images:
|
101 |
img_bytes = pil_image_to_bytes(img)
|
102 |
+
contents.append(types.Part.from_bytes(data=img_bytes, mime_type="image/jpeg"))
|
|
|
|
|
|
|
|
|
103 |
|
104 |
# Generate content using Gemini
|
105 |
+
response = client.models.generate_content(
|
106 |
+
model="gemini-2.0-flash",
|
107 |
+
contents=contents
|
108 |
+
)
|
109 |
+
|
110 |
|
111 |
return response
|
112 |
|