From ee2471bb4ad8e190c1f2c1c47817046a2c4d6b30 Mon Sep 17 00:00:00 2001 From: Jules Laplace Date: Fri, 3 Jan 2020 15:35:26 +0100 Subject: adding biggan dataset stuff --- app/client/auth/auth.gate.js | 2 +- app/client/modules/biggan/biggan.tasks.js | 20 +++- app/client/modules/biggan/index.js | 10 ++ app/client/modules/biggan/views/biggan.new.js | 33 ++++++ app/client/modules/biggan/views/biggan.results.js | 105 +++++++++++++++++++ app/client/modules/biggan/views/biggan.show.js | 119 ++++++++++++++++++++++ 6 files changed, 287 insertions(+), 2 deletions(-) create mode 100644 app/client/modules/biggan/views/biggan.new.js create mode 100644 app/client/modules/biggan/views/biggan.results.js create mode 100644 app/client/modules/biggan/views/biggan.show.js (limited to 'app') diff --git a/app/client/auth/auth.gate.js b/app/client/auth/auth.gate.js index 40f244f..a75b22e 100644 --- a/app/client/auth/auth.gate.js +++ b/app/client/auth/auth.gate.js @@ -48,7 +48,7 @@ class AuthGate extends Component { render(){ const { auth, env, actions } = this.props if (env.production && !auth.initialized) { - console.log('loading auth') + // console.log('loading auth') return
Loading
} if (env.development || auth.isAuthenticated) { diff --git a/app/client/modules/biggan/biggan.tasks.js b/app/client/modules/biggan/biggan.tasks.js index 827add5..2aed088 100644 --- a/app/client/modules/biggan/biggan.tasks.js +++ b/app/client/modules/biggan/biggan.tasks.js @@ -7,6 +7,25 @@ import actions from '../../actions' import module from './biggan.module' +export const invert_task = (dataset, folder_id, epochs=1) => dispatch => { + dataset = dataset.name || dataset + if (dataset === 'PLACEHOLDER') return + const task = { + module: module.name, + activity: 'invert', + dataset, + opt: { + folder_id: folder_id, + } + } + if (!task.dataset) { + console.error("invert task: no dataset specified") + return + } + console.log(task) + return actions.queue.add_task(task) +} + export const live_task = (opt) => dispatch => { const task = { module: module.name, @@ -14,7 +33,6 @@ export const live_task = (opt) => dispatch => { dataset: 'biggan', opt } - console.log(task) console.log('add live task') return actions.queue.add_task(task) } diff --git a/app/client/modules/biggan/index.js b/app/client/modules/biggan/index.js index 6c94008..05d0213 100644 --- a/app/client/modules/biggan/index.js +++ b/app/client/modules/biggan/index.js @@ -5,6 +5,9 @@ import actions from '../../actions' import util from '../../util' +import BigGANNew from './views/biggan.new' +import BigGANShow from './views/biggan.show' +import BigGANResults from './views/biggan.results' import BigGANLive from './views/biggan.live' class router { @@ -19,6 +22,10 @@ class router { render(){ return (
+ + + +
) @@ -27,6 +34,9 @@ class router { function links(){ return [ + { url: '/biggan/new/', name: 'folders' }, + { url: '/biggan/datasets/', name: 'datasets' }, + { url: '/biggan/results/', name: 'results' }, { url: '/biggan/live/', name: 'live' }, ] } diff --git a/app/client/modules/biggan/views/biggan.new.js b/app/client/modules/biggan/views/biggan.new.js new file mode 100644 index 0000000..0d0f74f --- /dev/null +++ b/app/client/modules/biggan/views/biggan.new.js @@ -0,0 +1,33 @@ +import { h, Component } from 'preact' +import { bindActionCreators } from 'redux' +import { connect } from 'react-redux' +import { Link } from 'react-router-dom' +import util from '../../../util' + +import { Views } from '../../../common' + +import * as bigganActions from '../biggan.actions' +import bigganModule from '../biggan.module' + +function BigGANNew(props){ + return ( + + ) +} + +const mapStateToProps = state => ({ + biggan: state.module.biggan, +}) + +const mapDispatchToProps = (dispatch, ownProps) => ({ + actions: bindActionCreators(bigganActions, dispatch), +}) + +export default connect(mapStateToProps, mapDispatchToProps)(BigGANNew) + diff --git a/app/client/modules/biggan/views/biggan.results.js b/app/client/modules/biggan/views/biggan.results.js new file mode 100644 index 0000000..d76b301 --- /dev/null +++ b/app/client/modules/biggan/views/biggan.results.js @@ -0,0 +1,105 @@ +import { h, Component } from 'preact' +import { bindActionCreators } from 'redux' +import { Link } from 'react-router-dom'; +import { connect } from 'react-redux' +import util from '../../../util' + +import actions from '../../../actions' + +import * as bigganActions from '../biggan.actions' +import * as bigganTasks from '../biggan.tasks' + +import Loading from '../../../common/loading.component' +import { FileList, FileRow } from '../../../common/fileList.component' + +let yes_count = 0 + +class BigGANResults extends Component { + constructor(props){ + super() + if (!props.biggan.results) props.actions.load_results() + } + componentDidMount(){ + yes_count = 0 + } + render(){ + if (! this.props.biggan.results) return + + const { resultsFolder, results, renders, files } = this.props.biggan.results + // console.log(resultsFolder, results) + + return ( +
+
+

BigGAN Results

+
+
+ + { + let yes; + if (yes_count < 3) { + yes = confirm('Are you sure you want to delete this file?') + } else { + yes = true + } + if (yes) { + yes_count += 1 + console.log('delete: confirmed') + actions.file.destroy(file) + } + }} + /> +
+ +

renders on server

+ { + e.preventDefault() + e.stopPropagation() + console.log('picked a result', file) + this.handlePick(file) + }} + /> +
+ +

folders on server

+ { + e.preventDefault() + e.stopPropagation() + console.log('picked a result', file) + this.handlePick(file) + }} + /> + +
+
+ ) + } + handlePick(file){ + // this.props.audioPlayer.play(file) + } +} + +const mapStateToProps = state => ({ + biggan: state.module.biggan, +}) + +const mapDispatchToProps = (dispatch, ownProps) => ({ + actions: bindActionCreators(bigganActions, dispatch), + remote: bindActionCreators(bigganTasks, dispatch), + // audioPlayer: bindActionCreators(audioPlayerActions, dispatch), +}) + +export default connect(mapStateToProps, mapDispatchToProps)(bigganResults) diff --git a/app/client/modules/biggan/views/biggan.show.js b/app/client/modules/biggan/views/biggan.show.js new file mode 100644 index 0000000..8d85f87 --- /dev/null +++ b/app/client/modules/biggan/views/biggan.show.js @@ -0,0 +1,119 @@ +import { h, Component } from 'preact' +import { bindActionCreators } from 'redux' +import { connect } from 'react-redux' +import util from '../../../util' + +import * as bigganActions from '../biggan.actions' +import * as bigganTasks from '../biggan.tasks' + +import { Loading, CurrentTask, FileList, FileRow } from '../../../common' +import DatasetForm from '../../../dataset/dataset.form' +import NewDatasetForm from '../../../dataset/dataset.new' +import UploadStatus from '../../../dataset/upload.status' + +import DatasetComponent from '../../../dataset/dataset.component' + +import bigganModule from '../biggan.module' + +class BigGANShow extends Component { + constructor(props){ + super(props) + this.datasetActions = this.datasetActions.bind(this) + } + componentWillMount(){ + const id = this.props.match.params.id || localStorage.getItem('biggan.last_id') + console.log('load dataset:', id) + const { match, biggan, actions } = this.props + if (id === 'new') return + if (id) { + if (parseInt(id)) localStorage.setItem('biggan.last_id', id) + if (! biggan.folder || biggan.folder.id !== id) { + actions.load_directories(id) + } + } else { + this.props.history.push('/biggan/new/') + } + } + render(){ + const { biggan, match, history } = this.props + const { folderLookup } = (biggan.data || {}) + const folder = (folderLookup || {})[biggan.folder_id] || {} + + return ( +
+
+
+

{folder ? folder.name : }

+ +
+
+
+ {folder && folder.name && folder.name !== 'unsorted' && + + } +
+ + +
+
+ + { + e.preventDefault() + e.stopPropagation() + console.log('picked a file', file) + }} + datasetActions={this.datasetActions} + /> +
+ ) + } + datasetActions(dataset, isFetching=false, isProcessing=false){ + const { biggan, remote } = this.props + const input = biggan.data.fileLookup[dataset.input[0]] + if (! input) return null + if (input.name && input.name.match(/(gif|jpe?g|png)$/i)) return null + return ( +
+
+
+ {dataset.isBuilt + ?
+ {'fetched '} + remote.clear_cache_task(dataset)}>rm +
+ : isFetching + ?
+ {'fetching'} +
+ :
+ remote.fetch_task(input.url, input.id, dataset.name)}>fetch +
+ } +
+ ) + } +} + +const mapStateToProps = state => ({ + biggan: state.module.biggan, +}) + +const mapDispatchToProps = (dispatch, ownProps) => ({ + actions: bindActionCreators(bigganActions, dispatch), + remote: bindActionCreators(bigganTasks, dispatch), +}) + +export default connect(mapStateToProps, mapDispatchToProps)(BigGANShow) -- cgit v1.2.3-70-g09d2