Example #1
0
def completeListener():
    # empty lists to contain the atriibute and
    tag = []
    attribute = []
    innerElement = []
    innerText = []

    # listen to various tag and their inner nested tags
    tag, innerElement = listenTag()

    # some tag like img,vedio,input,href need atrribute like src,type,href
    mustHaveAtrribute = ['img', 'input', 'vedio', 'a']

    # listen to associated attribute
    if tag in mustHaveAtrribute:
        attribute = listenAttribute(tag)

    # now we have to listen to the innertext if there is any
    print(f'is there any inner text associated with {tag} ?')
    openion = listener()
    if 'yes' in openion:
        innerText = listener()

    # After tag and attributes are clear make appropriate data to pass to react
    data = {
        "element": tag,
        "innerText": innerText,
        "attributes": attribute,
        "innerElement": innerElement
    }
    return data
Example #2
0
def handleSelect():
    optionNo = 1
    options = []
    while True:
        print(f"speak option {optionNo}")
        value = listener()
        option = {"tag": 'option', "value": value}
        options.append(option)
        print(options)
        print(f"is their more option?")
        openion = listener()
        if 'yes' not in openion.lower():
            return options
        optionNo += 1
Example #3
0
def handleList():
    listNo = 1
    listCollection = []
    while True:
        print(f"{listNo} list value")
        value = listener()
        list = {"tag": "li", "value": value}
        listCollection.append(list)
        print(f'updatedli: {listCollection} ')
        print(f"want to add more? 'Yes' to continue")
        openion = listener()
        if "yes" not in openion.lower():
            return listCollection
        listNo = listNo + 1
Example #4
0
def listenTableData(row):
    tag = 'td'
    values = []
    if row == 1:
        tag = 'th'
    # now to listen data in a table row we loop
    while True:
        print(f"speak {tag} data")
        spoken = listener()
        data = {"tag": tag, "value": spoken}
        values.append(data)
        print(f"more {tag}? speak 'Yes' to continue")
        openion = listener()
        if "yes" not in openion.lower():
            return values
Example #5
0
def listenUser(recType):
    # dont be confuse this while is for the case when tag is not recognized
    while True:
        # create the bot
        botName = "Jony"
        if recType == 1:
            print("Let's hear tag!")
        else:
            print("Let's hear atriibute! ")

        # listen to voice command
        sentence = listener()
        print('Jony: I hear>', sentence)

        # see if the user say quit to end the tag
        if 'quit' in sentence:
            return 'quit'
        elif 'finish' in sentence:
            return 'quit'
        else:
            print(f'you: {sentence}')
            # if command is understandable synthesize the tag

            tag = synthesizeTag(sentence, botName, recType)
            print(f'jony: {tag}')
            if tag != None:
                return tag
Example #6
0
def handleSrc():
    while True:
        print(f'jony: speak src value')
        spoken = listener()
        # file are with different extension like .jpg,jpeg,mp4 we have to find appropriate file
        fileToOpen = completeFile(spoken)
        if fileToOpen:
            return fileToOpen
def handleSelect():
    optionNo = 1
    options = []
    while True:
        engine.say('Please give me an option')
        engine.runAndWait()
        print(f"speak option {optionNo}")
        value = listener()
        option = {"tag": 'option', "value": value}
        options.append(option)
        print(options)
        engine.say('Is there more option sir say yes to add more')
        engine.runAndWait()
        print(f"is their more option?.. say yes to add more")
        openion = listener()
        if 'yes' not in openion.lower():
            return options
        optionNo += 1
def handleList():
    listNo = 1
    listCollection = []
    while True:
        engine.say('Give me a list value')
        engine.runAndWait()
        print(f"{listNo} list value")
        value = listener()
        list = {"tag": "li", "value": value}
        listCollection.append(list)
        print(f'updatedli: {listCollection} ')
        engine.say('Do you want to add more sir please say yes to continue')
        engine.runAndWait()
        print(f"want to add more? 'Yes' to continue")
        openion = listener()
        if "yes" not in openion.lower():
            return listCollection
        listNo = listNo + 1
Example #9
0
def handleNav():
    tags = []
    while True:
        tag = completeListener()
        tags.append(tag)
        print('is there more <a> tags? yes to continue')
        tag = anchorHandler()
        openion = listener()
        if 'yes' not in openion:
            return tags
Example #10
0
def handleForm():
    tags = []
    while True:
        tag = completeListener()
        tags.append(tag)
        print('till now ', tags)
        print('is there more tag inside form?')
        openion = listener()
        if 'yes' not in openion:
            return tags
def listenTableData(row):
    tag = 'td'
    values = []
    if row == 1:
        tag = 'th'
    # now to listen data in a table row we loop
    while True:
        engine.say('Give me a data.')
        engine.runAndWait()
        print(f"speak {tag} data")
        spoken = listener()
        data = {"tag": tag, "value": spoken}
        values.append(data)
        engine.say('Is there more table data say yes to have it')
        engine.runAndWait()
        print(f"more {tag}? speak 'Yes' to continue")
        openion = listener()
        if "yes" not in openion.lower():
            return values
Example #12
0
def listenType():
    possibleType = [
        'date', 'email', 'file', 'password', 'radio', 'checkbox', 'search',
        'submit', 'image', 'nubmer'
    ]
    while True:
        print('Jony: speak type:')
        value = listener()

        if value in possibleType:
            return value
        else:
            print('No such type!')
Example #13
0
def handleTable():
    row = 1
    rowData = []
    while True:
        print(f'Table row {row}')
        rowInner = listenTableData(row)
        intermidiateRow = {"tag": 'tr', "innerElement": rowInner}
        rowData.append(intermidiateRow)
        print(rowData)
        print(f"want to add more rows? 'Yes' to continue")
        openion = listener()
        if "yes" not in openion.lower():
            return rowData
        row = row + 1
Example #14
0
def listenAttribute(tag):
    attribute = []
    # For each tag there can be multiple attributes listen to the attributes
    while True:
        listenedAttribute = listenUser(2)
        if listenedAttribute is not None:
            if 'quit' in listenedAttribute:
                return attribute
            # we have to handle some special attribute like src,values of option
            if listenedAttribute == "src":
                value = handleSrc()
            else:
                print(f'jony: speak {listenedAttribute} value')
                value = listener()
            attrValue = {"attr": listenedAttribute, "value": value}
            attribute.append(attrValue)
def handleForm():
    tags = []

    while True:
        tag = completeListener()
        tags.append(tag)
        engine.say('Is there more tag inside form')
        engine.runAndWait()

        print('is there more tag inside form?')
        engine.say('Till now')
        engine.runAndWait()

        print('till now ', tags)
        openion = listener()
        if 'yes' not in openion:
            return tags
Example #16
0
    # apply softmax to find probability of predicted class
    probs = torch.softmax(output, dim=1)
    prob = probs[0][predicted.item()]

    # loop for pattern to see if any pattern matches
    if prob.item() > 0.75:
        for intent in intents['intents']:
            if tag == intent["tags"]:
                # {random.choice(intent['tags'])}
                print(f"{botName}: {tag} \n => {prob.item()} ")
    else:
        print(f"{botName}: I do not understand...")


while True:
    sentence = listener()

    # check if listener return an error
    if 'error!' in sentence:
        print(f"{botName}: I do not understand...")

    else:
        print(f'you: {sentence}')  # sentence =input('you:')
        if sentence == 'quit':
            break
        giveResponse(sentence)

        # create a json file
        file = open("websitedata.txt", "a+")
        file.write('this is the line')
        file.close()