import React, { Component } from 'react' import { bindActionCreators } from 'redux' import { connect } from 'react-redux' import * as actions from './faceAnalysis.actions' import { Loader } from '../common' const errors = { bbox: (

No face found

{"Sorry, we didn't detect a face in that image. "} {"Please choose an image where the face is large and clear."}
), nomatch: (

{"You're clear"}

{"No images in this dataset match your face. We show only matches above 70% probability."}
), error: (

{"No matches found"}

{"Sorry, an error occured."}
), not_an_image: (

{"Not an image"}

{"Sorry, the file you uploaded was not recognized as an image. Please upload a JPG or PNG image and try again."}
), } class FaceAnalysisResult extends Component { render() { const { result, timing } = this.props const { data, error, loading, message } = result let { step, total } = data || {} // console.log(step, total) if (loading) { return (

Uploading...

) } if (error) { // console.log(error) let errorMessage = errors[error] || errors.error return (
{errorMessage}
) } // console.log(result) if (!total) { return (
) } // console.log(data.data) const results = [ 'blur_fn', 'points_3d_68', 'landmarks_3d_68', 'landmarks_2d_68', 'pose', ].map(tag => { if (tag in data.data) { const { title, url } = data.data[tag] return (
{title}
) } return null }).filter(a => a) const statisticsLabels = ['Age (Real)', 'Age (Apparent)', 'Gender', 'Beauty score', 'Emotion'] const statistics = [ 'age_real', 'age_apparent', 'gender', 'beauty', 'emotion' ].map((tag, i) => { if (tag in data.data.statistics) { return ( {statisticsLabels[i]} {data.data.statistics[tag]} ) } return null }).filter(a => a) return (
{results}
{!!statistics.length && ( {statistics}
)}
Step {step} / {total} {message}
Query {step === total ? 'took' : 'timer:'} {(timing / 1000).toFixed(2)} s.
) } } const mapStateToProps = state => ({ query: state.faceAnalysis.query, result: state.faceAnalysis.result, timing: state.faceAnalysis.timing, options: state.faceAnalysis.options, }) const mapDispatchToProps = dispatch => ({ actions: bindActionCreators({ ...actions }, dispatch), }) export default connect(mapStateToProps, mapDispatchToProps)(FaceAnalysisResult)