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.
- Setup & Installation
- API Key Configuration
- Initializing the Gemini Model
- Generating Text Responses
- Handling Multimodal Inputs
- Error Handling
- License
Dependencies:
- Python 3.x
google-generativeailibrary- Jupyter Notebook (for interactive execution)
Installation:
!pip install google-generativeaiThis cell installs the official Google Gemini API Python SDK.
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_KEYwith an actual key from Google AI Studio.
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).
response = model.generate_content("Explain quantum computing in simple terms.")
print(response.text)- Workflow:
- Sends a prompt to the Gemini API.
- Returns and prints the generated response.
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.
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).
This project is licensed under the MIT License.
Author: Tanzeel
Repository: GEMINI_API_01
- Clone the repo:
git clone https://github.com/CodewithTanzeel/GEMINI_API_01.git
- Open the notebook in Jupyter/Colab.
- Replace
YOUR_API_KEYwith a valid key. - Run cells sequentially.
- For advanced usage, refer to the official Gemini API docs.
- Avoid hardcoding API keys in shared notebooks. Use environment variables instead.