diff options
| author | Jules Laplace <julescarbon@gmail.com> | 2019-01-13 18:08:49 +0100 |
|---|---|---|
| committer | Jules Laplace <julescarbon@gmail.com> | 2019-01-13 18:08:49 +0100 |
| commit | 6710b9f7f223acd01ac82171d9f9f4eb577f5885 (patch) | |
| tree | e8328f43f107e5c5dbef2aeb8b2746239a44508a /client/faceAnalysis | |
| parent | 47b6ae0f8ad2f49692222bb0c800e7ba1eb4b94b (diff) | |
serializing image failed, writing to tmp file instead
Diffstat (limited to 'client/faceAnalysis')
| -rw-r--r-- | client/faceAnalysis/faceAnalysis.actions.js | 39 | ||||
| -rw-r--r-- | client/faceAnalysis/faceAnalysis.query.js | 10 | ||||
| -rw-r--r-- | client/faceAnalysis/faceAnalysis.reducer.js | 1 | ||||
| -rw-r--r-- | client/faceAnalysis/faceAnalysis.result.js | 54 |
4 files changed, 28 insertions, 76 deletions
diff --git a/client/faceAnalysis/faceAnalysis.actions.js b/client/faceAnalysis/faceAnalysis.actions.js index 6a318b5d..860d3292 100644 --- a/client/faceAnalysis/faceAnalysis.actions.js +++ b/client/faceAnalysis/faceAnalysis.actions.js @@ -8,7 +8,7 @@ import { get, post } from '../util' // urls const url = { - upload: () => process.env.API_HOST + '/task/upload/sleep', + upload: () => process.env.API_HOST + '/task/upload/blur', } export const publicUrl = { } @@ -45,22 +45,6 @@ export const updateOptions = opt => dispatch => { // API functions -export const upload = (payload, file) => dispatch => { - // const { options } = store.getState().faceAnalysis - const tag = 'task' - const fd = new FormData() - fd.append('query_img', file) - // fd.append('limit', options.perPage) - // if (!query) { - dispatch(loading(tag)) - // } - post(url.upload(payload.dataset), fd) - .then(data => { - dispatch(loaded(tag, data)) - }) - .catch(err => dispatch(error(tag, err))) -} - // task polling const POLL_DELAY = 500 @@ -68,12 +52,31 @@ let pollTimeout = null export const poll = (payload, taskURL) => dispatch => { clearTimeout(pollTimeout) + console.log('polling...') get(taskURL) .then(data => { + console.log('poll', data) dispatch(polled(data)) - if (!data.complete) { + if (data.state !== 'error' && data.state !== 'complete') { pollTimeout = setTimeout(() => poll(payload, taskURL), POLL_DELAY) } }) .catch(err => dispatch(error('result', err))) } + +export const upload = (payload, file) => dispatch => { + const tag = 'task' + const fd = new FormData() + fd.append('query_img', file) + dispatch(loading(tag)) + post(url.upload(), fd) + .then(data => { + console.log('loaded!', tag, data) + dispatch(loaded(tag, data)) + const { result, taskURL } = data + if (result && taskURL) { + poll(payload, taskURL)(dispatch) + } + }) + .catch(err => dispatch(error(tag, err))) +} diff --git a/client/faceAnalysis/faceAnalysis.query.js b/client/faceAnalysis/faceAnalysis.query.js index 6b92b70d..a79e3e78 100644 --- a/client/faceAnalysis/faceAnalysis.query.js +++ b/client/faceAnalysis/faceAnalysis.query.js @@ -2,7 +2,7 @@ import React, { Component } from 'react' import { bindActionCreators } from 'redux' import { connect } from 'react-redux' -import { Loader } from '../common' +import { Loader, UploadImage } from '../common' import * as actions from './faceAnalysis.actions' // function parse_bbox(s) { @@ -37,13 +37,7 @@ class FaceAnalysisQuery extends Component { <div className='uploadContainer'> <div style={style}> {image ? null : <img src="/assets/img/icon_camera.svg" />} - <input - type="file" - name="img" - accept="image/*" - onChange={this.upload.bind(this)} - required - /> + <UploadImage onUpload={this.upload.bind(this)} /> </div> {result.loading && ( <div className='loading' style={style}> diff --git a/client/faceAnalysis/faceAnalysis.reducer.js b/client/faceAnalysis/faceAnalysis.reducer.js index 54a6d5eb..de6e5b0a 100644 --- a/client/faceAnalysis/faceAnalysis.reducer.js +++ b/client/faceAnalysis/faceAnalysis.reducer.js @@ -28,6 +28,7 @@ export default function faceAnalysisReducer(state = initialState(), action) { } case types.faceAnalysis.error: + console.log('error', action) return { ...state, [action.tag]: { error: action.err }, diff --git a/client/faceAnalysis/faceAnalysis.result.js b/client/faceAnalysis/faceAnalysis.result.js index b825a0cb..f9531eba 100644 --- a/client/faceAnalysis/faceAnalysis.result.js +++ b/client/faceAnalysis/faceAnalysis.result.js @@ -26,12 +26,6 @@ const errors = { {"Sorry, an error occured."} </div> ), - bad_dataset: ( - <div> - <h2>{""}</h2> - {""} - </div> - ), not_an_image: ( <div> <h2>{"Not an image"}</h2> @@ -42,19 +36,19 @@ const errors = { class FaceAnalysisResult extends Component { render() { - const { dataset } = this.props.payload - const { query, distances, results, loading, error } = this.props.result + const { query, task, result, loading, error } = this.props.result console.log(this.props.result) if (loading) { return ( <div className='result'> <div> <Loader /><br /> - <h2>Searching...</h2> + <h2>Uploading...</h2> </div> </div> ) } + console.log(task, result) if (error) { // console.log(error) let errorMessage = errors[error] || errors.error @@ -62,53 +56,13 @@ class FaceAnalysisResult extends Component { <div className='result'>{errorMessage}</div> ) } - if (!results) { - return <div className='result'></div> - } - if (!results.length) { - return ( - <div className='result'>{errors.nomatch}</div> - ) - } - const els = results.map((result, i) => { - const distance = distances[i] - const { uuid } = result.file_record - const { x, y, w, h } = result.face_roi - const { fullname, gender, description, images } = result.identity - const bbox = { - left: (100 * x) + '%', - top: (100 * y) + '%', - width: (100 * w) + '%', - height: (100 * h) + '%', - } - // console.log(bbox) - return ( - <div key={i}> - <div className='img'> - <img src={'https://megapixels.nyc3.digitaloceanspaces.com/v1/media/' + dataset + '/' + uuid + '.jpg'} /> - <div className='bbox' style={bbox} /> - </div> - {fullname} {'('}{gender}{')'}<br/> - {description}<br/> - {courtesyS(images, 'image')}{' in dataset'}<br /> - {Math.round((1 - distance) * 100)}{'% match'} - </div> - ) - }) + if (!task && !result) return return ( <div className='result'> <div className="about"> - <h2>Did we find you?</h2> - {'These faces matched images in the '} - <b><tt>{dataset}</tt></b> - {' dataset with over 70% probability.'} - <br /> <small>Query took {query.timing.toFixed(2)} seconds</small> </div> - <div className='results'> - {els} - </div> </div> ) } |
