def publish_test(): script_dict = clean_script(values) test = AIE_DRIVE.get_item_by_path(*FILE_PATH[0:2], 'Testing', 'Test.xlsx') wb = WorkBook(test) ws = wb.get_worksheet('Scripts') _range = ws.get_range(f"A2:T{len(script_dict['script']) + 1}") _range.update(values=script_dict['script'])
def get_bot_definition(): testing_fol = AIE_DRIVE.get_item_by_path(*FILE_PATH, 'EN-US', 'Testing') bot_definition = testing_fol.get_item('bot_definition.xlsx') bot_template_fol = testing_fol.get_item('bot definition files') intent_clarification = [] intents = [] sample_utterances = [] slots = [] slot_types = [] first = 1 sheets = [(intent_clarification, 'Intent Clarification', 1), (intents, 'Intents', 1), (sample_utterances, 'Sample Utterances', 2), (slots, 'Slots', 5), (slot_types, 'Slot Types', 2)] for item in bot_template_fol.get_items(): if item.is_file: print(item.name) matches = re.findall(r'(\d+)', item.name) last = int(matches[1]) wb = WorkBook(item) for sheet_list, sheet_name, stop_index in sheets: ws = wb.get_worksheet(sheet_name) _range = ws.get_used_range() values = [ row[:stop_index] for row in _range.values[3:] if row[0] != '' ] sheet_list.extend(values) combo_name = f"bot_definition_MC{first:03d}-MC{last:03d}.xlsx" bot_definition.copy(testing_fol, name=combo_name) combo_file = testing_fol.get_item(combo_name) wb = WorkBook(combo_file) alpha = 'ABCDEFGHIJ' for sheet_list, sheet_name, stop_index in sheets: ws = wb.get_worksheet(sheet_name) _range = ws.get_range( f"A4:{alpha[stop_index - 1]}{len(sheet_list) + 3}") _range.update(values=sheet_list)
def get_bot_template(): testing_fol = AIE_DRIVE.get_item_by_path(*FILE_PATH, 'EN-US', 'Testing') bot_template = testing_fol.get_item('bot_template.xlsx') bot_template_fol = testing_fol.get_item('bot template files') convos = [] scripts = [] first = 1 for item in bot_template_fol.get_items(): if item.is_file: print(item.name) matches = re.findall(r'(\d+)', item.name) last = int(matches[1]) wb = WorkBook(item) convos_ws = wb.get_worksheet('Conversations') convos_range = convos_ws.get_used_range() convos_values = [ row[:5] for row in convos_range.values[3:] if row[0] != '' ] convos.extend(convos_values) scripts_ws = wb.get_worksheet('Scripts') scripts_range = scripts_ws.get_used_range() scripts_values = [ [row[0], agent, *row[2:8]] for row in scripts_range.values[3:] if (row[0] != '' and (agent := row[1].replace('"', ''))) ] scripts.extend(scripts_values) print(f"{len(convos)=}, {len(scripts)=}") combo_name = f"bot_template_MC{first:03d}-MC{last:03d}.xlsx" bot_template.copy(testing_fol, name=combo_name) combo_file = testing_fol.get_item(combo_name) wb = WorkBook(combo_file) convos_ws = wb.get_worksheet('Conversations') convos_range = convos_ws.get_range(f"A4:E{len(convos) + 3}") convos_range.update(values=convos) scripts_ws = wb.get_worksheet('Scripts') scripts_range = scripts_ws.get_range(f"A4:H{len(scripts) + 3}") scripts_range.update(values=scripts)
def prepes(domain): es_fol = AIE_DRIVE.get_item_by_path(*FILE_PATH, 'ES-US', '_Training') domain_fol = es_fol.get_item(domain).get_item('Intent') feedback = domain_fol.get_item('Feedback') wkdir = domain_fol.get_item('Working') if not wkdir: domain_fol.create_child_folder('Working') wkdir = domain_fol.get_item('Working') template = domain_fol.get_item('Template.xlsx') for item in wkdir.get_items(): print(f"Deleting {item.name}") item.delete() for item in feedback.get_items(): print(f"Copying {item.name}") template.copy(wkdir, name=item.name) copied_item = wkdir.get_item(item.name) wb = WorkBook(item) ws = wb.get_worksheet('Intent Clarification') _range = ws.get_used_range() new_wb = WorkBook(copied_item) new_ws = new_wb.get_worksheet('Intent Clarification') new_range = new_ws.get_range(_range.address) new_range.update(values=_range.values) es_intent_prep(script_dict, item, copied_item, domain)
from largebot import AIE_DRIVE, FILE_PATH, PROJ_CONFIG from welo365 import WorkBook import pandas as pd PROJ_DRIVE, PROJ_PATH = PROJ_CONFIG.get('EN-US') #en_utts = ACCOUNT.get_item_by_url( # # 'https://welocalize.sharepoint.com/:x:/r/sites/msteams_08dd34-AmazonLex-LargeBot/_layouts/15/Doc.aspx?sourcedoc=%7BF5A2D6CA-D4F1-40F1-90C1-85E0FBE4FF3A%7D&file=FINAL_EN_Tr_Utts_MC_Drop11.xlsx&action=default&mobileredirect=true' # 'https://welocalize.sharepoint.com/:x:/r/sites/msteams_08dd34-AmazonLex-LargeBot/_layouts/15/Doc.aspx?sourcedoc=%7B66D65B6F-8DC4-4222-9BBB-08A3EFE77169%7D&file=12302020_EN-US_Training-Data_Drop2_Utts.xlsx&action=default&mobileredirect=true' # ) en_utts = PROJ_DRIVE.get_item_by_path(*PROJ_PATH, 'EN-US', '_Training', 'Delivery Prep', '50% Drop', 'Drop2 for ES_us slots populated.xlsx') es_temp = AIE_DRIVE.get_item_by_path( *FILE_PATH[:-1], 'Data Sheet Templates', 'es-US', 'TEMPLATE - es-US_Training Data__Utterance Creation Sheet.xlsx') en_wb = WorkBook(en_utts) wss = list(en_wb.get_worksheets()) print(f"{wss=}") for en_ws, dom, last_row in zip(wss, ['MC', 'Fi'], [24001, 6001]): if dom == 'MC': continue print(f"{en_ws.name=}") print(f"{dom=}, {last_row=}") _range = en_ws.get_range(f"A1:J{last_row}") columns, *values = _range.values en_df = pd.DataFrame(values, columns=columns) en_df['IntentNameTranslation'] = None en_df.drop(columns=['Sample Utterance'], inplace=True)
from largebot import AIE_DRIVE, AIE_PATH from welo365 import WorkBook en_intent_fol = AIE_DRIVE.get_item_by_path(*AIE_PATH, 'Data Sheet Templates', 'es-US', 'Intent', 'EN') es_intent_fol = AIE_DRIVE.get_item_by_path(*AIE_PATH, 'Data Sheet Templates', 'es-US', 'Intent', 'ES') es_intent_template = AIE_DRIVE.get_item_by_path( *AIE_PATH, 'Data Sheet Templates', 'es-US', 'TEMPLATE - es-US_Training Data__Intent_Slot Creation Sheet.xlsx') def translate_intents(en_values): es_values = [] translation = '' divider = '' slot_type_name = '' for intent_id, intent_name, intent_description, _, _, _, slot_id, slot_name, slot_required, slot_name_built_in, _, slot_prompt, slot_value, slot_value_built_in in en_values: es_values.append([ intent_id, intent_name, translation, intent_description, divider, slot_id, slot_name, translation, slot_required, slot_name_built_in, divider, slot_prompt, translation, slot_value, translation, slot_type_name, slot_value_built_in ]) return es_values for en_item in en_intent_fol.get_items(): es_name = en_item.name.replace('EN', 'ES') print(es_name) es_intent_template.copy(es_intent_fol, name=es_name)
from largebot import AIE_DRIVE from welo365 import WorkBook import pandas as pd import re DROP_PATH = [ 'Amazon Web Services, Inc', 'Lex LargeBot (Akshat)', 'Deliveries', '10% Drop' ] deliverINT_file = AIE_DRIVE.get_item_by_path( *DROP_PATH, '12142020_EN-US_Training-Data_Drop1_IntS.xlsx') deliverUTT_file = AIE_DRIVE.get_item_by_path( *DROP_PATH, '12142020_EN-US_Training-Data_Drop1_Utts.xlsx') def get_worksheet(infile, sheet_name): wb = WorkBook(infile) return wb.get_worksheet(sheet_name) def get_df(worksheet): columns, *values = worksheet.get_used_range().values return pd.DataFrame(values, columns=columns) deliverINT = get_worksheet(deliverINT_file, 'Intent_Slot Creation') dfINT = get_df(deliverINT) deliverUTT = get_worksheet(deliverUTT_file, 'Utterances') dfUTT = get_df(deliverUTT)
from welo365 import WorkBook from largebot.botter.amazon import Utterer from termcolor import colored, cprint def print_row(row): colors = ('red', 'blue', 'yellow', 'green', 'magenta', 'cyan') for i, cell in enumerate(row): cprint(cell, colors[(i + len(colors)) % len(colors)], 'on_white', end='\t') print('') scripts = AIE_DRIVE.get_item_by_path(*FILE_PATH[0:2], 'Testing', 'Test.xlsx') ints_del = AIE_DRIVE.get_item_by_path(*FILE_PATH[0:2], 'Testing', 'ints_delivery.xlsx') test_int = AIE_DRIVE.get_item_by_path(*FILE_PATH[0:2], 'Testing', 'ES_Tr_Ints_MC_090.xlsx') wb = WorkBook(scripts) ws = wb.get_worksheet('Scripts') _range = ws.get_used_range() _, *values = _range.values values = [row[:12] for row in values] amazon = Utterer() def clean_script(values: list): script_dict = {}
from welo365 import WorkBook from largebot import AIE_DRIVE, FILE_PATH import pandas as pd from ruamel.yaml import YAML from ruamel.yaml.scalarstring import SingleQuotedScalarString from pathlib import Path postponexl = AIE_DRIVE.get_item_by_path(*FILE_PATH, 'EN-US', 'Testing', 'POSTPONE', 'BOT TEMPLATE AND DEF.xlsx') wb = WorkBook(postponexl) ws = wb.get_worksheet('Scripts') _range = ws.get_range('A3:K93') columns, *values = _range.values df = pd.DataFrame(values, columns=columns) df.replace(to_replace='FALSE', value=False, inplace=True) df.replace(to_replace='TRUE', value=True, inplace=True) df = df.applymap(lambda x: x.strip() if isinstance(x, str) else x) intents = {} slot_types = {} conversations = {} for row in df.itertuples(name='row'): if row.IntentName not in intents: intents[row.IntentName] = { 'name': row.IntentName, 'sample_utterances': [row.SampleResponse], 'slots': [] }