From 5c018b3f2c2c47371546d210240836057d1ea5bb Mon Sep 17 00:00:00 2001 From: Jules Laplace Date: Tue, 5 Jun 2018 22:02:19 +0200 Subject: set menu dropdown from url. make pix2pix views --- app/client/modules/pix2pix/views/pix2pix.live.js | 253 +++++++++++++++++++++++ app/client/modules/pix2pix/views/pix2pix.new.js | 16 ++ app/client/modules/pix2pix/views/pix2pix.show.js | 115 +++++++++++ 3 files changed, 384 insertions(+) create mode 100644 app/client/modules/pix2pix/views/pix2pix.live.js create mode 100644 app/client/modules/pix2pix/views/pix2pix.new.js create mode 100644 app/client/modules/pix2pix/views/pix2pix.show.js (limited to 'app/client/modules/pix2pix/views') diff --git a/app/client/modules/pix2pix/views/pix2pix.live.js b/app/client/modules/pix2pix/views/pix2pix.live.js new file mode 100644 index 0000000..fc6bc9b --- /dev/null +++ b/app/client/modules/pix2pix/views/pix2pix.live.js @@ -0,0 +1,253 @@ +import { h, Component } from 'preact' +import { bindActionCreators } from 'redux' +import { connect } from 'react-redux' + +import Player from '../../../common/player.component' +import ParamGroup from '../../../common/paramGroup.component' +import Slider from '../../../common/slider.component' +import Select from '../../../common/select.component' +import Button from '../../../common/button.component' + +import { startRecording, stopRecording, saveFrame } from '../../../live/player' + +import * as liveActions from '../../../live/live.actions' + +class Pix2PixLive extends Component { + constructor(props){ + super() + props.actions.get_params() + props.actions.list_checkpoints() + props.actions.list_sequences() + this.changeCheckpoint = this.changeCheckpoint.bind(this) + this.changeEpoch = this.changeEpoch.bind(this) + this.changeSequence = this.changeSequence.bind(this) + this.seek = this.seek.bind(this) + this.togglePlaying = this.togglePlaying.bind(this) + this.toggleRecording = this.toggleRecording.bind(this) + } + componentWillUpdate(nextProps) { + if (nextProps.opt.checkpoint_name && nextProps.opt.checkpoint_name !== this.props.opt.checkpoint_name) { + this.props.actions.list_epochs(nextProps.opt.checkpoint_name) + } + } + changeCheckpoint(checkpoint_name){ + this.props.actions.load_epoch(checkpoint_name, 'latest') + } + changeEpoch(epoch_name){ + this.props.actions.load_epoch(this.props.opt.checkpoint_name, epoch_name) + } + changeSequence(sequence){ + console.log('got sequence', sequence) + this.props.actions.load_sequence(sequence) + } + seek(percentage){ + const frame = Math.floor(percentage * (parseInt(this.props.frame.sequence_len) || 1) + 1) + this.props.actions.seek(frame) + } + togglePlaying(){ + if (this.props.opt.processing) { + this.props.actions.pause() + } else { + this.props.actions.play() + } + } + toggleRecording(){ + if (this.props.opt.recording){ + stopRecording() + this.props.actions.pause() + } else { + startRecording() + } + } + render(){ + return ( +
+ +
+
+ + + + + + + + +
+
+ + + + + + + + + + + + + + + + +
+
+ + + + + + + + + + + + + + + + + + + +
+
+
+ ) + } +} +function timeInSeconds(n){ + return (n / 10).toFixed(1) + ' s.' +} +const mapStateToProps = state => ({ + opt: state.live.opt, + frame: state.live.frame, + checkpoints: state.live.checkpoints, + epochs: state.live.epochs, + sequences: state.live.sequences, +}) + +const mapDispatchToProps = (dispatch, ownProps) => ({ + actions: bindActionCreators(liveActions, dispatch) +}) + +export default connect(mapStateToProps, mapDispatchToProps)(Pix2PixLive) diff --git a/app/client/modules/pix2pix/views/pix2pix.new.js b/app/client/modules/pix2pix/views/pix2pix.new.js new file mode 100644 index 0000000..173777c --- /dev/null +++ b/app/client/modules/pix2pix/views/pix2pix.new.js @@ -0,0 +1,16 @@ +import { h, Component } from 'preact' +import { bindActionCreators } from 'redux' +import { connect } from 'react-redux' +import * as util from '../../../util' + +import NewDatasetForm from '../../../dataset/dataset.new' + +import pix2pixModule from '../pix2pix.module' + +export default function Pix2PixNew ({ history }) { + return ( +
+ +
+ ) +} diff --git a/app/client/modules/pix2pix/views/pix2pix.show.js b/app/client/modules/pix2pix/views/pix2pix.show.js new file mode 100644 index 0000000..b4cdc50 --- /dev/null +++ b/app/client/modules/pix2pix/views/pix2pix.show.js @@ -0,0 +1,115 @@ +import { h, Component } from 'preact' +import { bindActionCreators } from 'redux' +import { connect } from 'react-redux' +import * as util from '../../../util' + +import * as pix2pixActions from '../pix2pix.actions' +import * as pix2pixTasks from '../pix2pix.tasks' + +import Loading from '../../../common/loading.component' +import DatasetForm from '../../../dataset/dataset.form' +import NewDatasetForm from '../../../dataset/dataset.new' +import UploadStatus from '../../../dataset/upload.status' +import { FileList, FileRow } from '../../../common/fileList.component' + +import DatasetComponent from '../../../dataset/dataset.component' + +import pix2pixModule from '../pix2pix.module' + +class Pix2pixShow extends Component { + constructor(props){ + super(props) + this.datasetActions = this.datasetActions.bind(this) + } + componentWillMount(){ + const id = this.props.match.params.id || localStorage.getItem('pix2pix.last_id') + console.log('load dataset:', id) + const { match, pix2pix, actions } = this.props + if (id === 'new') return + if (id) { + if (parseInt(id)) localStorage.setItem('pix2pix.last_id', id) + if (! pix2pix.folder || pix2pix.folder.id !== id) { + actions.load_directories(id) + } + } + } + render(){ + const { pix2pix, match, history } = this.props + const { folderLookup } = (pix2pix.data || {}) + const folder = (folderLookup || {})[pix2pix.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 { pix2pix, remote } = this.props + const input = pix2pix.data.fileLookup[dataset.input[0]] + if (! input) return null + if (input.name && input.name.match(/(gif|jpe?g|png)$/i)) return null + return ( +
+
+ remote.train_task(dataset, pix2pix.folder_id, 1)}>train + remote.train_task(dataset, pix2pix.folder_id, 2)}>2x + remote.train_task(dataset, pix2pix.folder_id, 4)}>4x + remote.train_task(dataset, pix2pix.folder_id, 6)}>6x + remote.train_task(dataset, pix2pix.folder_id, 18)}>18x +
+ {dataset.isBuilt + ?
+ {'fetched '} + remote.clear_cache_task(dataset)}>rm +
+ : isFetching + ?
+ {'fetching'} +
+ :
+ remote.fetch_task(input.url, input.id, dataset.name)}>fetch +
+ } +
+ ) + } +} + +const mapStateToProps = state => ({ + pix2pix: state.module.pix2pix, +}) + +const mapDispatchToProps = (dispatch, ownProps) => ({ + actions: bindActionCreators(pix2pixActions, dispatch), + remote: bindActionCreators(pix2pixTasks, dispatch), +}) + +export default connect(mapStateToProps, mapDispatchToProps)(Pix2pixShow) -- cgit v1.2.3-70-g09d2