Вот код:
Код: Выделить всё
def get_vision_response(pdf_file):
try:
genai.configure(api_key=GOOGLE_API_KEY)
model = genai.GenerativeModel(
model_name="gemini-1.5-pro-latest",
system_instruction=[
"You are a helpful transcriber that can accurately transcribe text from images and PDFs.",
"Your mission is to transcribe text from the provided PDF file.",
],
)
pdf_part = Part.from_data(pdf_file, mime_type="application/pdf")
prompt = "Please transcribe the text in this PDF document."
full_content = [prompt, pdf_part]
response = model.generate_content(full_content)
return response.text
except Exception as e:
print("An error occurred during the model invocation")
# Save the error message to a text file
with open("error_log.txt", "w") as error_file:
error_file.write(f"An error occurred: {str(e)}\n")
Произошла ошибка: не удалось создать Blob, ожидается Blob, dict или
изображение типа(
Код: Выделить всё
PIL.Image.ImageЗначение:
inline_data { mime_type: "application/pdf" data:
"%PDF-1.7\n %\302\265\302\266\n\n1 0 объект\n\nendobj\n\n2 0 объект\n\nendobj\n\n3 0 obj\n\nstream\nx\001\305\ 235\313\256t\307м\205\347\347)z\234\301Q\357[\200
\003+\201\221\241a\001\031\307Jd
\200\0238\377\373\003\371X\227E\262\252Z\323\3000$\365\256\033\271H\026k\025\367>\177\277\375\351\366\ 367\333\235\377=\266\375\366|\357\267\377\375\317\333\277\335\37
Кто-нибудь знает, как это исправить?
Подробнее здесь: https://stackoverflow.com/questions/786 ... gemini-api