View file src/colab/prompting_with_the_gemini_api.py - Download
# -*- coding: utf-8 -*-
"""prompting_with_the_gemini_api.ipynb
Automatically generated by Colab.
Original file is located at
https://colab.research.google.com/drive/1JJTm2vb_ma2ucy1yFwV0pLBOX2afffq5
https://learn.udacity.com/paid-courses/cd13416/lessons/b073b751-4cab-406f-8948-711f418f56eb/concepts/f4d07e44-3e76-4414-afed-0983c52f6511?_gl=1*1dwbif7*_gcl_au*NzUzOTY0ODM1LjE3Mjk4NDM5MjE.*_ga*ODU4NzU5MTk4LjE3MzAzODY3Mzc.*_ga_CF22GKVCFK*MTczMTkzNjUyNS4xMC4xLjE3MzE5MzY5MTAuNjAuMC4w
"""
!pip install -q -U google-generativeai
import google.generativeai as genai
from google.colab import userdata
GOOGLE_API_KEY = userdata.get('GOOGLE_API_KEY')
genai.configure(api_key=GOOGLE_API_KEY)
version = "models/gemini-1.5-flash"
model = genai.GenerativeModel(version)
model
prompt = "Create a free verse about pasta linguine. Make it descriptive about the shape, taste and texture of pasta. Make the poem at least five lines long."
response = model.generate_content(prompt)
print(response.text)
#!wget -O kitchen.jpeg https://video.udacity-data.com/topher/2024/June/667b8988_kitchen/kitchen.jpeg
!wget -O kitchen.jpeg https://dam.thdstatic.com/contentful/heroflattenimage/KI-HERO-DreamKitchenDSKsat.jpg
image_upload = genai.upload_file("kitchen.jpeg")
from PIL import Image
image = Image.open('kitchen.jpeg')
resized_image = image.resize((int(image.size[0]/2), int(image.size[1]/2)), Image.Resampling.NEAREST)
resized_image
prompt = """This image contains a kitchen with a seating area (four chairs).
Give a description of the following room, including the key components
and each of the colors (be specific about what exact shade) of the items.
Explain in what location we could place 5 pots and pans so that the kitchen
retains its minimalistic appeal and clutter doesn't increase substantially."""
model = genai.GenerativeModel("gemini-1.5-flash")
response = model.generate_content([prompt, image_upload])
print(response.text)
"""https://learn.udacity.com/paid-courses/cd13416/lessons/b073b751-4cab-406f-8948-711f418f56eb/concepts/ad4fd7ec-3111-43c4-ab73-0b03ee367d77?_gl=1*1dwbif7*_gcl_au*NzUzOTY0ODM1LjE3Mjk4NDM5MjE.*_ga*ODU4NzU5MTk4LjE3MzAzODY3Mzc.*_ga_CF22GKVCFK*MTczMTkzNjUyNS4xMC4xLjE3MzE5MzY5MTAuNjAuMC4w"""
model_name = "gemini-1.5-flash"
model = genai.GenerativeModel(model_name)
prompt = "Help me choose a fun way to spend my Friday night as a CS major at Berkeley in a single one-sentence idea"
response = model.generate_content(prompt)
print(response.text)