Skip to content

CodewithTanzeel/GEMINI_API_01

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 

Repository files navigation

GEMINI API Implementation

Author: Tanzeel

This project demonstrates how to interact with the Google Gemini API for generative AI tasks. Below is a step-by-step breakdown of the Jupyter Notebook (.ipynb) cells and their functionalities.


Table of Contents

  1. Setup & Installation
  2. API Key Configuration
  3. Initializing the Gemini Model
  4. Generating Text Responses
  5. Handling Multimodal Inputs
  6. Error Handling
  7. License

1. Setup & Installation

Dependencies:

  • Python 3.x
  • google-generativeai library
  • Jupyter Notebook (for interactive execution)

Installation:

!pip install google-generativeai

This cell installs the official Google Gemini API Python SDK.


2. API Key Configuration

import google.generativeai as genai
genai.configure(api_key="YOUR_API_KEY")
  • Functionality: Configures the Gemini API with your unique API key.
  • Note: Replace YOUR_API_KEY with an actual key from Google AI Studio.

3. Initializing the Gemini Model

model = genai.GenerativeModel('gemini-pro')
  • Purpose: Initializes the Gemini-Pro model for text-based tasks.
  • Variants:
    • gemini-pro: Text-only model.
    • gemini-pro-vision: Multimodal (text + images).

4. Generating Text Responses

response = model.generate_content("Explain quantum computing in simple terms.")
print(response.text)
  • Workflow:
    1. Sends a prompt to the Gemini API.
    2. Returns and prints the generated response.

5. Handling Multimodal Inputs

vision_model = genai.GenerativeModel('gemini-pro-vision')
response = vision_model.generate_content(["Describe this image:", uploaded_image])
  • Use Case: Processes image inputs (e.g., uploaded files or URLs) alongside text prompts.

6. Error Handling

try:
    response = model.generate_content("Unclear prompt")
except Exception as e:
    print(f"Error: {e}")
  • Goal: Catches and displays API errors (e.g., invalid prompts, rate limits).

7. License

This project is licensed under the MIT License.


Author: Tanzeel
Repository: GEMINI_API_01


How to Use

  1. Clone the repo:
    git clone https://github.com/CodewithTanzeel/GEMINI_API_01.git
  2. Open the notebook in Jupyter/Colab.
  3. Replace YOUR_API_KEY with a valid key.
  4. Run cells sequentially.

Notes

  • For advanced usage, refer to the official Gemini API docs.
  • Avoid hardcoding API keys in shared notebooks. Use environment variables instead.

About

A concise Jupyter Notebook demonstrating advanced Gemini API features including text generation (gemini-pro), multimodal processing (gemini-pro-vision), and robust error handling - optimized for AI/ML workflows.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors