"""
Face Detection
Detect faces and their emotions on picture
"""

name = "computer-vision/face-detection"
version = "1.0.1"

"""
Face Detection
Detects faces on publicly-accessible image URL
"""
usecase FaceDetection {
  input {
    """
    Image URL
    Publicly-accessible image URL
    """
    imageUrl! string!
  }

  result [{
    faces! [{
      faceRectangle! faceRectangle!
      landmarks! [landmark]!
      emotions! emotions!
    }]!
  }]!

  error {
    message! string!
    code! string!
  }

  example success {
    input {
      imageUrl = 'https://upload.wikimedia.org/wikipedia/commons/c/c3/RH_Louise_Lillian_Gish.jpg',
    }

    result [{
      faces = [
        {
          emotions = {
            anger = "veryUnlikely",
            happiness = "veryUnlikely",
            sadness = "veryUnlikely",
            surprise = "veryUnlikely",
          },
          faceRectangle = {
            bottomLeft = {
              x = 176,
              y = 34,
            },
            bottomRight ={
              x = 428,
              y = 34,
            },
            topLeft = {
              x = 176,
              y = 327,
            },
            topRight = {
              x = 428,
              y = 327,
            },
          },
          landmarks =[
            {
              kind = "leftPupil",
              x = 229.75856,
              y = 174.96147,
            },
            {
              kind = "rightPupil",
              x = 289.5152,
              y = 169.29749,
            },
            {
              kind = "eyebrowLeftOuter",
              x = 211.37524,
              y = 158.85571,
            },
            {
              kind = "eyebrowLeftInner",
              x = 232.82782,
              y = 154.77731,
            },
            {
              kind = "eyebrowRightOuter",
              x = 313.55548,
              y = 145.77417,
            },
            {
              kind = "noseTip",
              x = 234.91925,
              y = 216.38809,
            },
            {
              kind = "mouthLeft",
              x = 244.84465,
              y = 257.07285,
            },
            {
              kind = "mouthRight",
              x = 287.81973,
              y = 253.6265,
            },
            {
              kind = "noseRootRight",
              x = 268.56677,
              y = 223.62668,
            },
            {
              kind = "noseRootLeft",
              x = 240.72118,
              y = 226.80193,
            },
            {
              kind = "eyeLeftTop",
              x = 226.20166,
              y = 169.5451,
            },
            {
              kind = "eyeLeftInner",
              x = 240.20996,
              y = 174.60138,
            },
            {
              kind = "eyeLeftBottom",
              x = 228.97414,
              y = 180.8672,
            },
            {
              kind = "eyeLeftOuter",
              x = 221.64114,
              y = 176.38219,
            },
            {
              kind = "eyeRightTop",
              x = 289.28845,
              y = 160.4581,
            },
            {
              kind = "eyeRightOuter",
              x = 307.3009,
              y = 169.60486,
            },
            {
              kind = "eyeRightBottom",
              x = 291.20908,
              y = 176.04889,
            },
            {
              kind = "eyeRightInner",
              x = 275.35458,
              y = 172.26141,
            },
          ],
        },
      ],
    },
  ]}

  example fail {
    input {
      imageUrl = 'https://upload.wikimedia.org',
    }

    error {
      code = 14,
      message ="We can not access the URL currently. Please download the content and pass it in."
    }
  }

}


model emotions {
  happiness! likelihood!
  anger! likelihood!
  sadness! likelihood!
  surprise! likelihood!
}

model faceRectangle {
  topLeft! point!
  topRight! point!
  bottomLeft! point!
  bottomRight! point!
}

model likelihood enum {
  unknown
  veryUnlikely
  unlikely
  possible
  likely
  veryLikely
}

model landmark {
  kind! landmarkKind!
  x! number!
  y! number!
}

model landmarkKind enum {
  //Left eye
  leftPupil
  eyeLeftOuter
  eyeLeftTop
  eyeLeftBottom
  eyeLeftInner
  //Right eye
  rightPupil
  eyeRightOuter
  eyeRightTop
  eyeRightBottom
  eyeRightInner
  //Left eyebrow
  eyebrowLeftOuter
  eyebrowLeftInner
  //Right eyebrow
  eyebrowRightInner
  eyebrowRightOuter
  //Nose
  noseTip
  noseRootLeft
  noseRootRight
  //Mouth
  mouthLeft
  mouthRight
}

model point {
  x number
  y number
}