Skip to content

Commit

Permalink
Liveess Component update (aws-samples#37)
Browse files Browse the repository at this point in the history
Co-authored-by: Vineet <[email protected]>
  • Loading branch information
vineetkachhawaha and vineetAWS authored May 25, 2023
1 parent 40e45ee commit 47f1c4e
Showing 1 changed file with 8 additions and 82 deletions.
90 changes: 8 additions & 82 deletions src/frontend/src/Components/Liveness.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { AmplifyProvider } from '@aws-amplify/ui-react';
import React from "react";
import { useRef, useState } from "react";
import {
FaceLivenessDetector

Expand Down Expand Up @@ -30,39 +29,16 @@ function Liveness({ referenceImage, livenessImageData }) {
const [userSelectedConfidence, setuserSelectedConfidence] = React.useState(80);
const [open, setOpen] = React.useState(true);

const [error, setError] = useState(undefined);
// const [checkFailed, setCheckFailed] = useState(false);

const closeModal = () => setOpen(false);

// const drawRectangle = (image) => {
// console.log(image)
// var canvas = document.getElementById('refImage');
// if (canvas != null) {
// var imageWidth = canvas.width;
// var imageHeight = canvas.height;

// var left = imageWidth * image.ReferenceImage.BoundingBox.Left
// var top = imageHeight * image.ReferenceImage.BoundingBox.Top
// var width = imageWidth * image.ReferenceImage.BoundingBox.Width
// var height = imageHeight * image.ReferenceImage.BoundingBox.Height
// const context = canvasRef.current.getContext("2d");
// context.strokeStyle = "#75FF33";
// context.lineWidth = 0.5;
// context.strokeRect(left, top, width, height)
// }
// };

const setReferenceImage = (image) => {
//image.userSelectedConfidence = document.getElementById("custId").value
console.log(userSelectedConfidence)
image.userSelectedConfidence = localStorage.getItem('userSelectedConfidence')
setImageData(image)
referenceImage(image);
};

const handleStartLiveness = () => {
console.log("Start")
const fetchCreateLiveness = async () => {
API.get("identityverification", "start-liveness-session").then(response => {
setSessionID(response.body.SessionId);
Expand All @@ -75,7 +51,6 @@ function Liveness({ referenceImage, livenessImageData }) {
};

const setSliderValue = (value) => {
// document.getElementById('custId').value = value
localStorage.setItem('userSelectedConfidence', value);
setuserSelectedConfidence(value)
};
Expand All @@ -88,7 +63,6 @@ function Liveness({ referenceImage, livenessImageData }) {
const onUserCancel = () => {
setSessionID(null);
handleStartLiveness()
setError(undefined);
};


Expand All @@ -115,32 +89,22 @@ function Liveness({ referenceImage, livenessImageData }) {
}, [userSelectedConfidence]);


// const formatValue = (value) => {
// return `${value}%`;
// };

const handleConsent = () => {

setOpen(false)
localStorage.setItem('userConsent', true);
}

const handleGetLivenessDetection = async (sessionId) => {
console.log(sessionId)
console.log('handleGetLivenessDetection')
if (sessionId) {
const requestData = {
body: { "sessionid": sessionId },
headers: { "Content-Type": "application/json" },
body: { "sessionid": sessionId },
headers: { "Content-Type": "application/json" },
};
const data = await API.post('identityverification', 'liveness-session-result', requestData);
try {
const success = data.body.Status
const confidence = data.body.Confidence
data.body.Confidence = confidence
console.log('data.body.Confidence')
console.log(data.body.Confidence)
console.log(localStorage.getItem('userSelectedConfidence'))
setuserSelectedConfidence(localStorage.getItem('userSelectedConfidence'))
setReferenceImage(data.body)
if (confidence >= userSelectedConfidence) {
Expand All @@ -150,7 +114,6 @@ function Liveness({ referenceImage, livenessImageData }) {

}
} catch (err) {
console.log(err)
setReferenceImage({ "error": true })
return { isLive: false };
}
Expand Down Expand Up @@ -183,11 +146,11 @@ function Liveness({ referenceImage, livenessImageData }) {
>
This feature uses Amazon Web Services. Amazon Web Services may collect, store, and use biometric identifiers and biometric information ("biometric data") to compare an individual's image with a stored image for analysis, verification, fraud, and security purposes.</Heading> <Heading

level={6}
marginBottom={tokens.space.large}
fontWeight={tokens.fontWeights.light}
>
Amazon Web Services’ privacy policy will retain generated biometric information from this process. You provide your express, informed, written release and consent for Amazon Web Services to collect, use, and store your biometric data as described herein.
level={6}
marginBottom={tokens.space.large}
fontWeight={tokens.fontWeights.light}
>
Amazon Web Services’ privacy policy will retain generated biometric information from this process. You provide your express, informed, written release and consent for Amazon Web Services to collect, use, and store your biometric data as described herein.
</Heading><Flex
direction="row"
justifyContent="center"
Expand Down Expand Up @@ -245,24 +208,6 @@ function Liveness({ referenceImage, livenessImageData }) {
wrap="wrap"
gap="1rem"
>
{/* <canvas
id="refImage"
ref={canvasRef}
style={{
// width: "400px",
// height: "400px",
alignItems: "center", alignContent: "center",
backgroundImage: 'url("data:image/jpeg;base64,' + imageData.ReferenceImageBase64 + '")',
// backgroundSize: 'cover',
backgroundRepeat: 'no-repeat',
backgroundPosition: 'center',
height: "480px",
width: "640px"
}}
/> */}


<Image
src={"data:image/jpeg;base64," + imageData.ReferenceImageBase64}
alignItems="center" alignContent="center"
Expand Down Expand Up @@ -320,35 +265,16 @@ function Liveness({ referenceImage, livenessImageData }) {
<FaceLivenessDetector
sessionId={sessionId}
region={process.env.REACT_APP_REGION ? process.env.REACT_APP_REGION : "us-east-1"}
onError={(error) => {
setError(error); // sets the error state
}}
onUserCancel={onUserCancel}
onAnalysisComplete={async () => {
const response = await handleGetLivenessDetection(sessionId
);
console.log(response)
// if (!response.isLive) {
// setCheckFailed(true);
// }
const response = await handleGetLivenessDetection(sessionId);
}}

/>
</View>

</Flex>
</Card>
{/* {error ? (
<View style={{ zIndex: 'auto' }}>
<FaceLivenessErrorModal
error={error}
onRetry={
onUserCancel
}
/>
</View>
) : null} */}

</>
)}

Expand Down

0 comments on commit 47f1c4e

Please sign in to comment.