import os
from dotenv import load_dotenv
import google.generativeai as genai
import pathlib
# Load the environment variables from the .env file
load_dotenv()
# Retrieve the Google API key from environment variables
GOOGLE_API_KEY = os.getenv('GOOGLE_API_KEY')
model = genai.GenerativeModel('gemini-1.5-flash')
my_picture = {
'mime_type': 'image/png',
'data': pathlib.Path('image2.png').read_bytes()
}
prompt = "Describe this image in detail"
response = model.generate_content(
model="gemini-1.5-flash",
content=[prompt, my_picture]
)
print(response.text)
I Keep getting the error that,
GenerativeModel.generate_content() got an unexpected keyword argument ‘model’ but I’ve tried many ways to solve it, just doesn’t seem to work.
I’ve tried running this command : pip install –upgrade google.generativeai
And also this command: pip install –upgrade google-cloud-aiplatform
Still couldn’t get any results.
Tried going the other way around with this code:
import os
from dotenv import load_dotenv
import google.generativeai as genai
import pathlib
load_dotenv()
GOOGLE_API_KEY = os.getenv('GOOGLE_API_KEY')
genai.configure(api_key=GOOGLE_API_KEY)
def get_prompt_from_image(image_path, text_prompt):
image_data = pathlib.Path(image_path).read_bytes()
image_prompt = {
'mime_type': 'image/png',
'data': image_data
}
model = genai.GenerativeModel('gemini-1.5-flash')
response = model.generate_content(
model="gemini-1.5-flash",
content=[text_prompt, image_prompt]
)
return response.text
if __name__ == '__main__':
image_path = 'path_to_your_image.png'
text_prompt = "Describe this image."
prompt = get_prompt_from_image(image_path, text_prompt)
print(f'Generated Prompt: {prompt}')
And still same error.