Hello!
Is it possible to do this:
Process a PDF file with Gemini
passing the PDF as a base-64 encoded string instead of as a GS URI?
Thanks!
Hello,
Thank you for contacting Google Cloud Community!
Yes, it is possible to process a PDF file with Gemini by passing the PDF as a base-64 encoded string instead of as a GS URI. Here's how you can do it:
Encode the PDF file to base-64:
Create a Gemini request:
Send the request to Gemini:
Python
import requests
# Replace with your Gemini API endpoint and API key
api_endpoint = "https://api.gemini.com/v1/chat"
api_key = "YOUR_API_KEY"
# Base-64 encoded PDF string
pdf_base64 = "data:application/pdf;base64,YOUR_BASE64_ENCODED_PDF_HERE"
# Gemini request payload
payload = {
"prompt": "Analyze the content of this PDF document:",
"input": pdf_base64
}
headers = {
"Authorization": f"Bearer {api_key}"
}
response = requests.post(api_endpoint, json=payload, headers=headers)
if response.status_code == 200:
print(response.json())
else:
print("Error:", response.text)
Hello,
Thank you for your engagement regarding this issue. We haven’t heard back from you regarding this issue for sometime now. Hence, I'm going to close this issue which will no longer be monitored. However, if you have any new issues, Please don’t hesitate to create a new issue. We will be happy to assist you on the same.
Regards,
Jai Ade
Jaja,
Just want to confirm, are there extra costs associated with using uploaded file vs. base64 encoded string? For ex, storage usage or ingress/egress?
User | Count |
---|---|
2 | |
2 | |
1 | |
1 | |
1 |