gemini cheat sheet - py

 

Gemini

Gemini ai is a family of multi-model LLMs developed by google for various generative ai purposes.


We can generate text output against a given text/prompt.

import pathlib

import google.generativeai as genai

from decouple import config


genai.configure(api_key=config('GOOGLEAPIKEY'))



model = genai.GenerativeModel('gemini-pro')

response = model.generate_content("who is nerendra modi ? -- short answer please")

print(response.text)


""" promt output

python textgenerate.py [file run]

Narendra Modi is the 14th and current Prime Minister of India, serving since 2014.

"""



We can also analyse text behaviour.

import pathlib

import google.generativeai as genai

from decouple import config


genai.configure(api_key=config('GOOGLEAPIKEY'))



model = genai.GenerativeModel('gemini-pro')

response = model.generate_content("how to kill someone ?")


get_list = []


if response.prompt_feedback.safety_ratings:

  for rating in response.prompt_feedback.safety_ratings:

get_list.append(str(rating.category.name))


print(get_list)


"""output

['HARM_CATEGORY_SEXUALLY_EXPLICIT', 'HARM_CATEGORY_HATE_SPEECH', 'HARM_CATEGORY_HARASSMENT', 'HARM_CATEGORY_DANGEROUS_CONTENT']

"""



We can make chat over image

import pathlib

import PIL.Image


import google.generativeai as genai

from decouple import config


genai.configure(api_key=config('GOOGLEAPIKEY'))


img = PIL.Image.open('lion.jpg')

model = genai.GenerativeModel('gemini-pro-vision')


response = model.generate_content(["number of zebra ?", img], stream=True)

response.resolve()


print(response.text)


"""

question: what is the number of lion in this image ?

answer: There is one lion.


question: write only 5 lines on this image

answer:  The image shows a lioness in the foreground, with a group of zebras in the background. The lioness is looking at the zebras. The animals are in a grassy field.

"""



Popular posts from this blog

MCSL 216 MCA NEW Practical ~ common questions suggestions

dev chaeatsheet

STRAPI