# Explain code cells with Gemini assistance

This document describes how you can use
Gemini in Colab Enterprise, which is a product
in the [Gemini for Google Cloud](https://docs.cloud.google.com/gemini/docs/overview.md.txt) portfolio,
to help you explain code cells in a Colab Enterprise notebook.

Learn [how and when Gemini
for Google Cloud uses your data](https://docs.cloud.google.com/gemini/docs/discover/data-governance).

This document is intended for data analysts, data scientists, and
data developers who work with Colab Enterprise. It assumes you have
knowledge of how to write code in a notebook environment.

## Overview

Gemini in Colab Enterprise can help you explain code cells
in a Colab Enterprise notebook. You might want to do this when you're working
with someone else's notebook and want to get a quick understanding of what
the code does. Or you might need to remind yourself how parts of your notebook
work after a long period of time without working on it.

After you get an explanation of a code cell, you can browse any
included code snippets and review the sources. You can also use the
**Explain code** chat dialog to discuss the code and ask follow-up questions.
For more details, see [Explain a code cell](https://docs.cloud.google.com/colab/docs/explain-cells.md.txt#explain).

## Before you begin

> [!CAUTION]
> As an early-stage technology, Gemini for Google Cloud
> products can generate output that seems plausible but is factually incorrect. We recommend that you
> validate all output from Gemini for Google Cloud products before you use it.
> For more information, see
> [Gemini for Google Cloud and responsible AI](https://docs.cloud.google.com/gemini/docs/discover/responsible-ai.md.txt).

1. [Ensure that
   Gemini in Colab Enterprise is set up for your
   Google Cloud user account and project.](https://docs.cloud.google.com/gemini/docs/colab/set-up-gemini)

### Required roles


To get the permissions that
you need to use Gemini in Colab Enterprise,

ask your administrator to grant you the
following IAM roles on the project:

- [Colab Enterprise User](https://docs.cloud.google.com/iam/docs/roles-permissions/aiplatform.md.txt#aiplatform.colabEnterpriseUser) (`roles/aiplatform.colabEnterpriseUser`)
- [Gemini for Google Cloud User](https://docs.cloud.google.com/iam/docs/roles-permissions/cloudaicompanion.md.txt#cloudaicompanion.user) (`roles/cloudaicompanion.user`)


For more information about granting roles, see [Manage access to projects, folders, and organizations](https://docs.cloud.google.com/iam/docs/granting-changing-revoking-access.md.txt).


You might also be able to get
the required permissions through [custom
roles](https://docs.cloud.google.com/iam/docs/creating-custom-roles) or other [predefined
roles](https://docs.cloud.google.com/iam/docs/roles-overview#predefined).
One or more of the required roles includes the `dataform.repositories.list` permission. Users who are granted the `dataform.repositories.list` permission or the [Code Creator
(`roles/dataform.codeCreator`)](https://docs.cloud.google.com/dataform/docs/access-control#dataform.codeCreator) role in a project can list the names of code assets in that project by using the Dataform API or the Dataform command-line interface (CLI). Non-administrators using BigQuery Studio can only see code assets that they created or that were shared with them.

## Explain a code cell

To explain a code cell using Gemini for Google Cloud,
do the following:

1. In the Google Cloud console, go to
   the Colab Enterprise **My notebooks** page.

   [Go to My notebooks](https://console.cloud.google.com/agent-platform/colab/notebooks)
2. In the **Region** menu, select the region that contains your notebook.

3. Click the notebook that you want to open.

4. In your notebook, click a code cell that has code in it.

5. Click
   **Available
   AI features** , and then click **Explain code**.

   If you haven't already authorized the Data Science Agent, a brief dialog appears while
   Colab Enterprise authenticates your Google Account to the Data Science Agent.
6. An **Explain code** chat dialog appears that includes
   an explanation of your code.

   Read through the explanation, browse the example code snippets,
   and review the sources. Use this chat dialog to discuss the code and
   ask follow-up questions.
7. To close the **Explain code** dialog, click
   **Close**.

## Turn off Gemini in Colab Enterprise


To turn off Gemini in Colab Enterprise for a
Google Cloud project, an administrator must turn off the
Gemini for Google Cloud API. See
[Disabling services](https://docs.cloud.google.com/service-usage/docs/enable-disable.md.txt#disabling).


To turn off Gemini in Colab Enterprise for a specific user, an
administrator needs to revoke the
[Gemini for
Google Cloud User](https://docs.cloud.google.com/iam/docs/roles-permissions/cloudaicompanion#cloudaicompanion.user) (`roles/cloudaicompanion.user`) role for that user. See
[Revoke
a single IAM role](https://docs.cloud.google.com/iam/docs/granting-changing-revoking-access#revoke-single-role).

## What's next

- Read the [Gemini for Google Cloud
  overview](https://docs.cloud.google.com/gemini/docs/overview).

- For more ways to write and edit code with Gemini
  assistance, see the following:

  - [Chat about your notebook with Gemini](https://docs.cloud.google.com/colab/docs/chat.md.txt)
  - [Use code completion and code generation](https://docs.cloud.google.com/colab/docs/use-code-completion.md.txt)
  - [Explain and fix errors](https://docs.cloud.google.com/colab/docs/explain-errors.md.txt)
  - [Use the Data Science Agent](https://docs.cloud.google.com/colab/docs/use-data-science-agent.md.txt)
- Learn [how Gemini for Google Cloud uses
  your data](https://docs.cloud.google.com/gemini/docs/discover/data-governance).