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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
|
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 DatasetForm from '../../dataset/dataset.form'
import NewDatasetForm from '../../dataset/dataset.new'
import { FileList, FileRow } from '../../common/fileList.component'
const samplernnModule = {
name: 'samplernn',
datatype: 'audio',
}
class SampleRNNDatasets extends Component {
constructor(props){
super(props)
console.log('ba')
this.fileOptions = this.fileOptions.bind(this)
this.pickFile = this.pickFile.bind(this)
}
componentWillMount(){
const id = this.props.id || this.props.match.params.id || localStorage.getItem('samplernn.last_id')
console.log(id)
console.log('load dataset:', id)
const { match, samplernn, actions } = this.props
if (id === 'new') return
if (id) {
localStorage.setItem('samplernn.last_id', id)
if (! samplernn.folder || samplernn.folder.id !== id) {
console.log('load directories')
actions.load_directories(id)
}
}
}
pickFile(file){
console.log('pick', file)
}
fileOptions(file){
if (file.activity === 'url' && !file.dataset) {
if (this.props.runner.cpu.status !== 'IDLE') {
return (
<div className='gray'>
fetching...
</div>
)
} else {
return (
<div className='link' onClick={() => this.fetchURL(file.url)}>
fetch
</div>
)
}
}
return (
<div>
<div className='link' onClick={() => this.train(file)}>train</div>
{file.epoch == 0 && <div className='epochs'>{file.epochs} ep.</div>}
</div>
)
}
render(){
const { samplernn, match, history } = this.props
const id = this.props.id || localStorage.getItem('samplernn.last_id')
console.log(this.props.id)
if (this.props.id && this.props.id !== 'new') return null
if (samplernn.loading) {
console.log('loading')
return <span>Loading</span>
}
if (!samplernn.folder || !samplernn.data.folders.length) {
console.log('no folders, redirect to /new')
return history.push('/samplernn/new/')
}
console.log('render app')
const folder = samplernn.folder
console.log(folder)
if (!folder || !folder.name) return
console.log(folder.name)
return (
<div className='app'>
<div class='heading'>
<h1>{folder.name}</h1>
</div>
{folder.name !== 'unsorted' &&
<DatasetForm
title='Add Files'
module={samplernnModule}
folder={folder}
canUpload canAddURL
/>
}
{this.renderDataset()}
</div>
)
}
renderDataset(){
return (
<div class='rows params datasets'>
<div class='row dataset'>
<div class='col'>input</div>
<div class='col'></div>
<div class='col'>checkpoint</div>
<div class='col'>output</div>
</div>
{this.renderGroups()}
</div>
)
}
renderGroups(){
const { samplernn } = this.props
const folder = samplernn.folder
const { mapFn, sortFn } = util.sort.orderByFn('date desc')
const datasets = folder.datasets.map(mapFn).sort(sortFn).map(pair => {
const dataset = pair[1]
return (
<div className='row dataset'>
{this.props.beforeRow && this.props.beforeRow(dataset)}
<div className='col'>
{!!dataset.input.length &&
<FileList
files={dataset.input}
className='input_files'
fileListClassName=''
rowClassName='input_file'
options={this.fileOptions}
/>
}
</div>
<div className='col quiet'>
<div>{dataset.isBuilt ? 'cached' : ''}</div>
</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}
orderBy='epoch desc'
fields={'name date epoch size'}
/>
}
</div>
</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)
|