Skip to content

Commit f0233db

Browse files
authored
removing classifygif and all that relates to it (#819)
1 parent bbd68e8 commit f0233db

File tree

13 files changed

+80
-1712
lines changed

13 files changed

+80
-1712
lines changed

.all-contributorsrc

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,18 @@
3737
"content"
3838
]
3939
},
40+
{
41+
"login": "mazenchami",
42+
"name": "Mazen Chami",
43+
"avatar_url": "https://avatars.githubusercontent.com/u/9324607?v=4",
44+
"profile": "https://github.com/mazenchami",
45+
"contributions": [
46+
"doc",
47+
"code",
48+
"review",
49+
"test"
50+
]
51+
},
4052
{
4153
"login": "jstudenski",
4254
"name": "Jeff Studenski",

README.md

Lines changed: 35 additions & 77 deletions
Large diffs are not rendered by default.

__tests__/classifyGif.ts

Lines changed: 0 additions & 78 deletions
This file was deleted.
-6.72 MB
Binary file not shown.

example/manual-testing/data/index.html

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -60,10 +60,6 @@ <h3>Images</h3>
6060
<div class="main-item">
6161
<h3>Animations</h3>
6262
<div class="wrapper">
63-
<div class="item">
64-
<p>GIF animation</p>
65-
<img crossorigin="anonymous" class='animations' width="280" height="250" src="http://localhost/data/animations/smile.gif"></img>
66-
</div>
6763

6864
<div class="item">
6965
<p>WebP animation</p>
@@ -105,12 +101,6 @@ <h3>Animations</h3>
105101
.then(predictions => showResults(images[i], predictions, true))
106102
.catch(error => showError(images[i], error))
107103
}
108-
109-
if (images[i].classList[0] === 'animations') {
110-
model.classifyGif(images[i], { topk: 3, fps: 1 })
111-
.then(predictions => showResults(images[i], predictions))
112-
.catch(error => showError(images[i], error))
113-
}
114104
}
115105
})
116106

example/nsfw_demo/package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,7 @@
1717
"react-webcam": "^1.1.0",
1818
"seedrandom": "^3.0.1",
1919
"stream-browserify": "^3.0.0",
20-
"tether-drop": "^1.4.2",
21-
"victory": "^36.0.0"
20+
"tether-drop": "^1.4.2"
2221
},
2322
"scripts": {
2423
"start": "react-app-rewired start",

example/nsfw_demo/src/App.js

Lines changed: 15 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ class App extends Component {
3838
loading: true,
3939
fileType: null,
4040
hardReset: false,
41-
gifControl: null,
4241
currentModelName: 'mobilenetMid',
4342
}
4443

@@ -84,76 +83,29 @@ class App extends Component {
8483

8584
detectBlurStatus = (predictions, blurNSFW = this.state.blurNSFW) => {
8685
let droppedImageStyle = clean
87-
if (this.state.fileType === 'image/gif') {
88-
const deemedEvil = this.detectGifEvil(predictions)
89-
droppedImageStyle = deemedEvil > 0 && blurNSFW ? blurred : clean
90-
} else {
91-
if (blurNSFW) {
92-
switch (predictions[0].className) {
93-
case 'Hentai':
94-
case 'Porn':
95-
case 'Sexy':
96-
droppedImageStyle = blurred
97-
}
86+
if (blurNSFW) {
87+
switch (predictions[0].className) {
88+
case 'Hentai':
89+
case 'Porn':
90+
case 'Sexy':
91+
droppedImageStyle = blurred
9892
}
9993
}
10094
return droppedImageStyle
10195
}
10296

103-
detectGifEvil = (predictions) =>
104-
predictions
105-
.filter((c) => {
106-
return ['Hentai', 'Porn', 'Sexy'].includes(c[0].className)
107-
})
108-
.flat().length
109-
11097
checkContent = async () => {
11198
// Sleep bc it's grabbing image before it's rendered
11299
// Not really a problem of this library
113100
await this.sleep(100)
114101
const img = this.refs.dropped
115-
if (this.state.fileType === 'image/gif') {
116-
this.setState({
117-
message: `0% - Parsing GIF frames`,
118-
predictions: [],
119-
loading: true,
120-
})
121-
const predictions = await this.state.model.classifyGif(img, {
122-
topk: 1,
123-
setGifControl: (gifControl) => {
124-
this.setState({
125-
gifControl,
126-
})
127-
},
128-
onFrame: ({ index, totalFrames, predictions }) => {
129-
const percent = ((index / totalFrames) * 100).toFixed(0)
130-
this.setState({
131-
message: `${percent}% - Frame ${index} is ${predictions[0].className}`,
132-
})
133-
},
134-
})
135-
const deemedEvil = this.detectGifEvil(predictions)
136-
// If any frame is NSFW, blur it (if blur is on)
137-
const droppedImageStyle = this.detectBlurStatus(predictions)
138-
const gifMessage =
139-
deemedEvil > 0
140-
? `Detected ${deemedEvil} NSFW frames`
141-
: 'All frames look clean'
142-
this.setState({
143-
message: `GIF Result: ${gifMessage}`,
144-
predictions,
145-
droppedImageStyle,
146-
loading: false,
147-
})
148-
} else {
149-
const predictions = await this.state.model.classify(img)
150-
let droppedImageStyle = this.detectBlurStatus(predictions)
151-
this.setState({
152-
message: `Identified as ${predictions[0].className}`,
153-
predictions,
154-
droppedImageStyle,
155-
})
156-
}
102+
const predictions = await this.state.model.classify(img)
103+
let droppedImageStyle = this.detectBlurStatus(predictions)
104+
this.setState({
105+
message: `Identified as ${predictions[0].className}`,
106+
predictions,
107+
droppedImageStyle,
108+
})
157109
}
158110

159111
setFile = (file) => {
@@ -171,7 +123,7 @@ class App extends Component {
171123

172124
onDrop = (accepted, rejected) => {
173125
if (rejected.length > 0) {
174-
window.alert('JPG, PNG, WEBP, GIF only plz')
126+
window.alert('JPG, PNG, WEBP only plz')
175127
} else {
176128
let droppedImageStyle = this.state.blurNSFW ? blurred : clean
177129
this.setState({
@@ -236,7 +188,6 @@ class App extends Component {
236188
/>
237189
)
238190
} else {
239-
// SuperGif kills our React Component
240191
// Only way I can seem to revive it is
241192
// to force a full re-render of Drop area
242193
if (this.state.hardReset) {
@@ -246,7 +197,7 @@ class App extends Component {
246197
return (
247198
<Dropzone
248199
id="dropBox"
249-
accept="image/jpeg, image/png, image/gif, image/webp"
200+
accept="image/jpeg, image/png, image/webp"
250201
className="photo-box"
251202
onDrop={this.onDrop.bind(this)}
252203
>
@@ -299,7 +250,6 @@ class App extends Component {
299250
<Loading showLoading={this.state.loading} />
300251
<Results
301252
message={this.state.message}
302-
gifControl={this.state.gifControl}
303253
predictions={this.state.predictions}
304254
/>
305255
</main>

example/nsfw_demo/src/components/GifBar.js

Lines changed: 0 additions & 106 deletions
This file was deleted.

example/nsfw_demo/src/components/Results.js

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import React from 'react'
2-
import GifBar from './GifBar'
32

4-
// Render Text Prediction OR GifBar
3+
// Render Text Prediction
54
const renderPredictions = props => {
65
// only render if predictions is in singular format
76
if (props.predictions[0] && props.predictions[0].className) {
@@ -17,8 +16,6 @@ const renderPredictions = props => {
1716
</ul>
1817
</div>
1918
)
20-
} else if (props.predictions[0]) {
21-
return <GifBar data={props.predictions} gifControl={props.gifControl} />
2219
}
2320
}
2421

0 commit comments

Comments
 (0)