summaryrefslogtreecommitdiff
path: root/app/client/modules/samplernn/samplernn.datasets.js
blob: aa729a59d14ed452b157f9861332f4e37c0172fd (plain)
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
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 Dataset from '../../dataset/dataset.component'

import Group from '../../common/group.component'
import Slider from '../../common/slider.component'
import Select from '../../common/select.component'
import Button from '../../common/button.component'
import { FileList, FileRow } from '../../common/fileList.component'
import TextInput from '../../common/textInput.component'

class SampleRNNDatasets extends Component {
  constructor(props){
    super()
    this.fileOptions = this.fileOptions.bind(this)
    this.pickFile = this.pickFile.bind(this)
    let id = props.match.params.id || localStorage.getItem('samplernn.last_id')
    if (! id && props.location.pathname.match(/\/new\//)) {
      id = 'new'
    } else if (id) {
      localStorage.setItem('samplernn.last_id', id)
    }
    if (id && (! props.samplernn.folder || props.samplernn.folder.id !== id)) {
      props.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 } = this.props
    const folder = samplernn.folder
    if (!folder.name) return
    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'>
          <div className='col'>
            {!!dataset.input.length &&
              <FileList
                files={dataset.input}
                className='input_files'
                fileListClassName=''
                rowClassName='input_file'
              />
            }
          </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 (
      <div className='app'>
        <div className='heading'>
          <h2>SampleRNN</h2>
        </div>
        <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>
          {datasets}
        </div>
      </div>
    )
  }
}

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)