-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
230 additions
and
34 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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} /> | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> | ||
) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> | ||
) | ||
} | ||
} |
Oops, something went wrong.