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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
|
import { h, Component } from 'preact'
import { bindActionCreators } from 'redux'
import { connect } from 'react-redux'
import * as util from '../../util'
import * as samplernnActions from './samplernn.actions'
import actions from '../../actions'
import DatasetForm from '../../dataset/dataset.form'
import NewDatasetForm from '../../dataset/dataset.new'
import { FileList, FileRow } from '../../common/fileList.component'
import Loading from '../../common/loading.component'
const samplernnModule = {
name: 'samplernn',
datatype: 'audio',
}
class SampleRNNDatasets extends Component {
constructor(props){
super(props)
this.pickFile = this.pickFile.bind(this)
}
componentWillMount(){
const id = this.props.id
console.log('load dataset:', id, this.props.id)
const { match, samplernn, actions } = this.props
if (id === 'new') return
if (id) {
if (parseInt(id)) localStorage.setItem('samplernn.last_id', id)
if (! samplernn.folder || samplernn.folder.id !== id) {
actions.load_directories(id)
}
}
}
pickFile(file){
console.log('pick', file)
}
onDeleteFile(file){
const yes = confirm('Are you sure you want to delete this file?')
if (yes) {
actions.file.destroy(file)
}
}
render(){
const { samplernn, folder, match, history } = this.props
if (samplernn.loading) {
return <Loading progress={samplernn.progress} />
}
if (!samplernn.data.folders.length) {
console.log('no folders, redirect to /new')
return history.push('/samplernn/new/')
}
if (!folder || !folder.name) return
return (
<div class='rows params datasets'>
<div class='row row-heading dataset'>
<div class='col'>input</div>
<div class='col'>status</div>
<div class='col'>checkpoint</div>
<div class='col'>output</div>
</div>
{this.renderGroups()}
</div>
)
}
renderGroups(){
const { samplernn, folder, runner, onPickDataset, onPickFile, datasetActions } = this.props
const { datasetLookup, fileLookup } = samplernn.data
const { mapFn, sortFn } = util.sort.orderByFn('date desc')
const moduleOnCPU = runner && runner.cpu.task && runner.cpu.task.module === samplernnModule.name
const moduleOnGPU = runner && runner.gpu.task && runner.gpu.task.module === samplernnModule.name
const datasets = folder.datasets.map(name => datasetLookup[name]).map(mapFn).sort(sortFn).map(pair => {
const dataset = pair[1]
let status = ''
let isProcessing = false, isFetching = false
if (moduleOnGPU && runner.gpu.task.dataset === dataset) {
status = util.gerund(runner.gpu.task.activity)
isProcessing = true
} else if (moduleOnCPU && runner.cpu.task.activity === 'fetch' && runner.cpu.task.opt.file_id === dataset.input[0]) {
isProcessing = true
isFetching = true
}
return (
<div key={dataset.name} className='row dataset' onClick={() => onPickDataset && onPickDataset(dataset)}>
{this.props.beforeRow && this.props.beforeRow(dataset)}
<div className='col'>
{!!dataset.input.length &&
<FileList
files={dataset.input.map(id => fileLookup[id])}
className='input_files'
fileListClassName=''
rowClassName='input_file'
fields={'name date size delete'}
onClick={onPickFile}
onDelete={(file) => this.onDeleteFile(file)}
/>
}
</div>
<div className={[
'col', 'quiet',
(dataset.isBuilt ? 'built' : 'not_built'),
(isProcessing ? 'processing': 'not_processing')
].join(' ')}>
{this.props.datasetActions && this.props.datasetActions(dataset, isFetching, isProcessing)}
{status}
</div>
<div className='col checkpoint'>
{!!dataset.checkpoints.length &&
<FileRow
file={dataset.checkpoints[0]}
fields={'name date epoch'}
className='row checkpoint'
/>
}
</div>
<div className='col'>
{!!dataset.output.length &&
<FileList
files={dataset.output.map(id => fileLookup[id])}
orderBy='epoch desc'
fields={'name date epoch size'}
onPickFile={onPickFile}
onDelete={(file) => this.onDeleteFile(file)}
/>
}
</div>
{this.props.afterRow && this.props.afterRow(dataset)}
</div>
)
})
return datasets
}
}
const mapStateToProps = state => ({
samplernn: state.module.samplernn,
runner: state.system.runner,
task: state.task,
})
const mapDispatchToProps = (dispatch, ownProps) => ({
actions: bindActionCreators(samplernnActions, dispatch),
})
export default connect(mapStateToProps, mapDispatchToProps)(SampleRNNDatasets)
|