text: import os
  import cv2
  import math
  from typing import Text, Type
  from aiogram import types
  from aiogram.dispatcher.filters.builtin import Command, Text
  from aiogram.dispatcher import FSMContext
  from aiogram.types import message
  from middlewares.states.all_states import gender_person_in_photo_state
  
  
  from loader import dp
  
  @dp.message_handler(text="/cancel", state=gender_person_in_photo_state)
  async def cancel(message: types.Message, state: FSMContext):
      await message.answer("✅ Функция остановлена!\n\nВведите новую команду /commands")
      await state.finish()
  
  
  @dp.message_handler(Command("gender_person_in_photo"), state=None)
  async def gender_person_in_photo(message: types.Message, state: FSMContext):
      await message.answer('''Вы зашли в функцию по распознованию пола человека.\n
  Скиньте сюда фотографии, которые вам нужно обработать нейросетью!\n
  ❗️ Все фотографии, которые вы будете сюда скидывать автоматически будут обрабатываться в этой функции.
  ❗️ Если вам нужно её остановить, то введите /cancel''')
      await gender_person_in_photo_state.step1.set()
  
  
  
  @dp.message_handler(content_types="document", state=gender_person_in_photo_state)
  async def gender_person_in_photo_document(message: types.Message, state: FSMContext):
      await message.answer("Скиньте фото, а не документ")
  
  
  
  @dp.message_handler(content_types="photo", state=gender_person_in_photo_state.step1)
  async def gender_person_in_photo_photo(message: types.Message, state: FSMContext):
      temp = message.photo[-1].file_id
      await message.photo[-1].download(f"./handlers/gender_person_in_photo/temp/{temp}.jpg")
      res = await resolve(f"./handlers/gender_person_in_photo/temp/{temp}.jpg") # res = ["male", or "female"]
      os.remove(f"./handlers/gender_person_in_photo/temp/{temp}.jpg")
      if res == "No face detected":
          await message.reply("На этом фото нет лица")
      elif res[0] == "male":
          await message.reply("На этом фото изображен - мужчина")
      elif res[0] == "female":
          await message.reply("На этом фото изображена - женщина")
      else:
          await message.answer("‼️ Произошла ошибка, попробуйте скинуть изображение ещё раз")
  
  
  
  
  faceProto = "./handlers/gender_person_in_photo/data/opencv_face_detector.pbtxt"
  faceModel = "./handlers/gender_person_in_photo/data/opencv_face_detector_uint8.pb"
  genderProto = "./handlers/gender_person_in_photo/data/gender_deploy.prototxt"
  genderModel = "./handlers/gender_person_in_photo/data/gender_net.caffemodel"
  
  genderList = ["male", "female"]
  
  faceNet = cv2.dnn.readNet(faceModel, faceProto)
  genderNet = cv2.dnn.readNet(genderModel, genderProto)
  
  MODEL_MEAN_VALUES = (78.4263377603, 87.7689143744, 114.895847746)
  
  def highlight(net, frame, threshold = 0.7):
      frameOpencvDnn = frame.copy()
      height = frameOpencvDnn.shape[0]
      width = frameOpencvDnn.shape[1]
  
      blob = cv2.dnn.blobFromImage(frameOpencvDnn, 1.0, (300, 300), [104, 117, 123], True, False)
  
      net.setInput(blob)
      detections = net.forward()
      faceboxes = []
  
      for i in range(detections.shape[2]):
          confidence = detections[0, 0, i, 2]
          if confidence > threshold:
              x1 = int(detections[0, 0, i, 3] * width)
              y1 = int(detections[0, 0, i, 4] * height)
              x2 = int(detections[0, 0, i, 5] * width)
              y2 = int(detections[0, 0, i, 6] * height)
              faceboxes.append([x1, y1, x2, y2])
  
      return frameOpencvDnn, faceboxes
  
  async def resolve(image):
      video = cv2.VideoCapture(image if image else 0)
      padding = 20
  
      while cv2.waitKey(1) < 0:
          hasFrame, frame = video.read()
  
          if not hasFrame:
              cv2.waitKey()
              break
  
          resultImg, faceboxes = highlight(faceNet, frame)
          if not faceboxes:
              return "No face detected"
  
          genders = []
          for facebox in faceboxes:
              face = frame[
  		max(0, facebox[1] - padding) : min(facebox[3] + padding, frame.shape[0] - 1),
                  max(0, facebox[0] - padding) : min(facebox[2] + padding, frame.shape[1] - 1)
              ]
  
              blob = cv2.dnn.blobFromImage(face, 1.0, (227, 227), MODEL_MEAN_VALUES, swapRB=False)
              genderNet.setInput(blob)
              genderPreds = genderNet.forward()
  
              gender = genderList[genderPreds[0].argmax()]
              genders.append(gender)
              return genders
      