def fr():
    with open('images.json', 'r') as f:
        images = json.load(f)
    #print(images)
    #print('1')
    cam = cv2.VideoCapture(0)
    time.sleep(0.1)
    s, img = cam.read()
    imwrite("pic.jpg", img)
    cam.release()
    name = 'unknown'
    for i in images:
        #print('images/{}'.format(images[i]))
        known_image = face_recognition.load_image_file('images/{}'.format(
            images[i]))
        unknown_image = face_recognition.load_image_file("pic.jpg")
        known_encoding = face_recognition.face_encodings(known_image)[0]
        try:
            unknown_encoding = face_recognition.face_encodings(
                unknown_image)[0]
            results = face_recognition.compare_faces([known_encoding],
                                                     unknown_encoding)
        except:
            print('Goffredo: "Face not found')
            return
        if results[0] == True:
            name = i
            #os.remove("pic.jpg")
    if name == 'unknown':
        say('Hello, what is your name?', 'en')
        fname = inp(4, 'name')
        text = recognise(fname).lower()
        try:
            li = text.split(' ')
            li.remove('my')
            li.remove('name')
            li.remove('is')
            name = li[0]
        except:
            name = text
        os.rename('pic.jpg', 'images/{}.jpg'.format(name))
        images[name] = '{}.jpg'.format(name)
    #print(name)
    #print(images)
    with open("images.json", 'w') as f:
        json.dump(images, f)
    say("Hello, {}!".format(name), 'en')
    return
Пример #2
0
def serie_a(text):
    bs = bs4.BeautifulSoup(
        requests.get('https://www.skysports.com/serie-a-table').content,
        'lxml')
    tables = bs.find_all('table')
    df = pd.read_html(str(tables[0]))[0]
    df = df.set_index('Team').rename(columns={'#': 'Pos'}).drop('Last 6', 1)
    pos = int(df.loc['AC Milan'].Pos)
    pts = int(df.loc['AC Milan'].Pts)
    say(
        f'AC Milan are currently in position {pos} in the Serie A, with {pts} points.',
        'en')
    say('Would you like to see the whole Serie A table?', 'en')
    fname = inp(3, 'ques')
    ans = recognise(fname)
    if 'yes' in ans:
        print(f'##\n{df}\n##')
        return
    if 'no' in ans:
        return
Пример #3
0
def info(x):
    y = x["main"]
    temperature = round(y["temp"] - 273.15, 2)
    pressure = y['pressure']
    humidity = y["humidity"]
    feels_like = round(y["feels_like"] - 273.15, 2)
    temp_max = round(y['temp_max'] - 273.15, 2)
    temp_min = round(y['temp_min'] - 273.15, 2)
    wind_speed = round(x["wind"]['speed'] * 1.94, 2)
    if x["wind"]['deg'] in range(23, 68):
        wind_dir = 'North East'
    elif x["wind"]['deg'] in range(68, 113):
        wind_dir = 'East'
    elif x["wind"]['deg'] in range(113, 158):
        wind_dir = 'South East'
    elif x["wind"]['deg'] in range(158, 203):
        wind_dir = 'East'
    elif x["wind"]['deg'] in range(203, 248):
        wind_dir = 'South West'
    elif x["wind"]['deg'] in range(248, 293):
        wind_dir = 'West'
    elif x["wind"]['deg'] in range(293, 338):
        wind_dir = 'North West'
    else:
        wind_dir = 'North'
    desc = x["weather"][0]["description"]
    loc = x["name"]
    print('##\nWeather in {}: {}\n##'.format(loc, desc))
    say('[The current weather in {} is: {}'.format(loc, desc), 'en')
    say('Would you like more info?', 'en')
    fname = inp(3, 'ques')
    text = recognise(fname)
    if 'yes' in text:
        print(
            '## \nTemperature: {} (degrees celcius) \n-feels like: {} \n-max: {} \n-min: {} '
            .format(temperature, feels_like, temp_max, temp_min))
        print(
            'Humidity: {}% \nAtmospheric pressure (in hPa unit): {} \nWind speed (knots): {} \nWind direction (deg): {} ({}erly)\n##'
            .format(humidity, pressure, wind_speed, x["wind"]['deg'],
                    wind_dir))
        say(
            '''[The temperature is {} degrees with a maximum of {} and a minimum of {}.
The humidity is {} percent and the wind is {} knots from the {}
'''.format(temperature, temp_max, temp_min, humidity, wind_speed, wind_dir),
            'en')
        return
    if 'no' in text:
        return
def translate(text):
    li = text.lower().split(' ')
    #tml(li)
    try:
        pos1 = li.index('translate')
    except:
        pos1 = li.index('say')
    text = ' '.join(li[pos1 + 1:-2])
    lang = li[-1]
    if lang == 'chinese':
        lang = 'chinese (simplified)'
    code = gt.LANGCODES[lang]
    translator = Translator()
    final = translator.translate(text, scr='en', dest=code)
    say('{} in {} is:'.format(text, lang), 'en')
    try:
        say(final.text, final.dest)
    except:
        say(final.text, 'en')
    return
Пример #5
0
def chat(text):
    re = str(bot.get_response(text))
    say(re,'en')
    return