1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
|
import { h, Component } from 'preact'
import { bindActionCreators } from 'redux'
import { connect } from 'react-redux'
import 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)
}
} else {
this.props.history.push('/pix2pix/new/')
}
}
render(){
const { pix2pix, match, history } = this.props
const { folderLookup } = (pix2pix.data || {})
const folder = (folderLookup || {})[pix2pix.folder_id] || {}
return (
<div className='app pix2pix'>
<div class='heading'>
<div class='spaced'>
<h1>{folder ? folder.name : <Loading />}</h1>
<UploadStatus />
</div>
</div>
{folder && folder.name && folder.name !== 'unsorted' &&
<DatasetForm
title='Add Files'
module={pix2pixModule}
folder={folder}
canUpload canAddURL
/>
}
<DatasetComponent
loading={pix2pix.loading}
progress={pix2pix.progress}
id={pix2pix.folder_id}
module={pix2pixModule}
data={pix2pix.data}
folder={folder}
history={history}
onPickFile={(file, e) => {
e.preventDefault()
e.stopPropagation()
console.log('picked a file', file)
}}
datasetActions={this.datasetActions}
/>
</div>
)
}
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 (
<div>
<div class={'actions'}>
<span class='link' onClick={() => remote.train_task(dataset, pix2pix.folder_id, 1)}>train</span>
<span class='link' onClick={() => remote.train_task(dataset, pix2pix.folder_id, 2)}>2x</span>
<span class='link' onClick={() => remote.train_task(dataset, pix2pix.folder_id, 4)}>4x</span>
<span class='link' onClick={() => remote.train_task(dataset, pix2pix.folder_id, 6)}>6x</span>
<span class='link' onClick={() => remote.train_task(dataset, pix2pix.folder_id, 18)}>18x</span>
</div>
{dataset.isBuilt
? <div class='subtext'>
{'fetched '}
<span class='link' onClick={() => remote.clear_cache_task(dataset)}>rm</span>
</div>
: isFetching
? <div class='subtext'>
{'fetching'}
</div>
: <div class='subtext'>
<span class='link' onClick={() => remote.fetch_task(input.url, input.id, dataset.name)}>fetch</span>
</div>
}
</div>
)
}
}
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)
|