Skip to content

Commit

Permalink
Separate screens
Browse files Browse the repository at this point in the history
  • Loading branch information
wylie39 committed Mar 5, 2021
1 parent 9f3bf9e commit 8b0c0bb
Show file tree
Hide file tree
Showing 6 changed files with 230 additions and 34 deletions.
169 changes: 169 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@
"@teachablemachine/image": "^0.8.4",
"@tensorflow/tfjs": "^3.2.0",
"blueimp-load-image": "^5.14.0",
"bootstrap": "^4.6.0",
"react": "16.13.1",
"react-bootstrap": "^1.5.1",
"react-dom": "16.13.1",
"react-scripts": "3.4.3"
},
Expand Down
39 changes: 14 additions & 25 deletions src/App.js
Original file line number Diff line number Diff line change
@@ -1,49 +1,38 @@
import React from 'react'
import Upload from './components/upload'
import Results from './components/results'
import { predict } from './helpers/helpers'

var loadImage = require('blueimp-load-image')

export default class App extends React.Component {
state = {
data: [],
results: [],
}

handleFiles = (e) => {
loadImage(
e.target.files[0],
async (img) => {
this.setState({ data: await predict(img) })
this.setState({ results: await predict(img) })
},
{ maxWidth: 600 } // Options
)
}
handleback = () => {
this.setState({ results: [] })
}

render() {
if (Object.keys(this.state.data).length) {
const list = this.state.data.sort()
if (Object.keys(this.state.results).length) {
return (
<div className="App">
<input
type="file"
accept="image/*"
onChange={this.handleFiles}
/>
{list.map((o, index) => (
<p>
{o.className} : {o.probability.toFixed(2)}
</p>
))}
</div>
<Results
handleback={this.handleback}
results={this.state.results}
/>
)
} else {
return (
<div className="App">
<input
type="file"
accept="image/*"
onChange={this.handleFiles}
/>
</div>
)
return <Upload handleFiles={this.handleFiles} />
}
}
}
20 changes: 20 additions & 0 deletions src/components/results.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import React from 'react'
import Button from 'react-bootstrap/Button'

export default class Results extends React.Component {
render() {
const list = this.props.results.sort()
return (
<div className="App">
<Button variant="primary" onClick={this.props.handleback}>
Back
</Button>
{list.map((o, index) => (
<p>
{o.className} : {o.probability.toFixed(2)}
</p>
))}
</div>
)
}
}
15 changes: 15 additions & 0 deletions src/components/upload.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import React from 'react'

export default class Upload extends React.Component {
render() {
return (
<div className="App">
<input
type="file"
accept="image/*"
onChange={this.props.handleFiles}
/>
</div>
)
}
}
Loading

0 comments on commit 8b0c0bb

Please sign in to comment.