<jupyter_start><jupyter_text>IntroductionIn this notebook, we will demonstrate how Google Sheets can be used as a simple medium for managing, updating, and evaluating Intents and Training Phrases in Dialogflow CX.Specifically, we will show how to extract Intents and Training Phrases from Dialogflow CX to Google Sheets. Prerequisites- Ensure you have a GCP Service Account key with the Dialogflow API Admin privileges assigned to it<jupyter_code>#If you haven't already, make sure you install the `dfcx-scrapi` library

!pip install dfcx-scrapi<jupyter_output><empty_output><jupyter_text>Imports<jupyter_code>from dfcx_scrapi.core.intents import Intents
from dfcx_scrapi.tools.dataframe_functions import DataframeFunctions<jupyter_output><empty_output><jupyter_text>User InputsIn the next section, we will collect runtime variables needed to execute this notebook.   This should be the only cell of the notebook you need to edit in order for this notebook to run.For this notebook, we'll need the following inputs:- `creds_path`: Your local path to your GCP Service Account Credentials- `agent_id`: Your Dialogflow CX Agent ID in String format- `google_sheet_name`: The name of your Google Sheet- `google_sheet_tab_write`:  The name of the tab in your Google Sheet where the data will be written<jupyter_code>creds_path = '<YOUR_CREDS_PATH_HERE>'
agent_id = '<YOUR_AGENT_ID_HERE>'
google_sheet_name = 'My Google Sheet Name'
google_sheet_tab_write = 'Write To My Tab Name'<jupyter_output><empty_output><jupyter_text>CX to SheetsHere, we'll demonstrate how to extract all of the Intents and Training Phrases from your Dialogflow CX Agent and push them to a Google Sheet. Prerequisites- In order for the `DataframeFunctions` class to interact with Google Sheets, you *must* share your Google Sheet with your Service Account email address.<jupyter_code># Instanstiate Classes
intents = Intents(creds_path)
dffx = DataframeFunctions(creds_path)

# Transform Intents into a DataFrame
df = intents.bulk_intent_to_df(agent_id)

# Push DataFrame to Google Sheets
dffx.dataframe_to_sheets(google_sheet_name, google_sheet_tab_write, df)

print('Total # of Intents = {}'.format(df.intent.nunique()))
print('Total # of Training Phrases = {}'.format(df.tp.nunique()))<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.06523642732049037, 'fraction_numerical': 0.0, 'mean_word_length': 6.491803278688525, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 19, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '4', 'dir': 'jupyter-structured-clean-dedup', 'id': '458973', 'license': 'Apache-2.0', 'n_tokens_mistral': 701, 'n_tokens_neox': 671, 'n_words': 259, 'path': 'examples/google_sheets_series/cx_to_sheets.ipynb', 'repo_name': 'karkipra/dfcx-scrapi', 'size': '2284'}