Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Removing GIF Support #819

Merged
merged 1 commit into from
Feb 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions .all-contributorsrc
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,18 @@
"content"
]
},
{
"login": "mazenchami",
"name": "Mazen Chami",
"avatar_url": "https://avatars.github.com/u/9324607?v=4",
"profile": "https://github.com/mazenchami",
"contributions": [
"doc",
"code",
"review",
"test"
]
},
{
"login": "jstudenski",
"name": "Jeff Studenski",
Expand Down
112 changes: 35 additions & 77 deletions README.md

Large diffs are not rendered by default.

78 changes: 0 additions & 78 deletions __tests__/classifyGif.ts

This file was deleted.

Binary file removed example/manual-testing/data/animations/smile.gif
Binary file not shown.
10 changes: 0 additions & 10 deletions example/manual-testing/data/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,6 @@ <h3>Images</h3>
<div class="main-item">
<h3>Animations</h3>
<div class="wrapper">
<div class="item">
<p>GIF animation</p>
<img crossorigin="anonymous" class='animations' width="280" height="250" src="http://localhost/data/animations/smile.gif"></img>
</div>

<div class="item">
<p>WebP animation</p>
Expand Down Expand Up @@ -105,12 +101,6 @@ <h3>Animations</h3>
.then(predictions => showResults(images[i], predictions, true))
.catch(error => showError(images[i], error))
}

if (images[i].classList[0] === 'animations') {
model.classifyGif(images[i], { topk: 3, fps: 1 })
.then(predictions => showResults(images[i], predictions))
.catch(error => showError(images[i], error))
}
}
})

Expand Down
3 changes: 1 addition & 2 deletions example/nsfw_demo/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@
"react-webcam": "^1.1.0",
"seedrandom": "^3.0.1",
"stream-browserify": "^3.0.0",
"tether-drop": "^1.4.2",
"victory": "^36.0.0"
"tether-drop": "^1.4.2"
},
"scripts": {
"start": "react-app-rewired start",
Expand Down
80 changes: 15 additions & 65 deletions example/nsfw_demo/src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ class App extends Component {
loading: true,
fileType: null,
hardReset: false,
gifControl: null,
currentModelName: 'mobilenetMid',
}

Expand Down Expand Up @@ -84,76 +83,29 @@ class App extends Component {

detectBlurStatus = (predictions, blurNSFW = this.state.blurNSFW) => {
let droppedImageStyle = clean
if (this.state.fileType === 'image/gif') {
const deemedEvil = this.detectGifEvil(predictions)
droppedImageStyle = deemedEvil > 0 && blurNSFW ? blurred : clean
} else {
if (blurNSFW) {
switch (predictions[0].className) {
case 'Hentai':
case 'Porn':
case 'Sexy':
droppedImageStyle = blurred
}
if (blurNSFW) {
switch (predictions[0].className) {
case 'Hentai':
case 'Porn':
case 'Sexy':
droppedImageStyle = blurred
}
}
return droppedImageStyle
}

detectGifEvil = (predictions) =>
predictions
.filter((c) => {
return ['Hentai', 'Porn', 'Sexy'].includes(c[0].className)
})
.flat().length

checkContent = async () => {
// Sleep bc it's grabbing image before it's rendered
// Not really a problem of this library
await this.sleep(100)
const img = this.refs.dropped
if (this.state.fileType === 'image/gif') {
this.setState({
message: `0% - Parsing GIF frames`,
predictions: [],
loading: true,
})
const predictions = await this.state.model.classifyGif(img, {
topk: 1,
setGifControl: (gifControl) => {
this.setState({
gifControl,
})
},
onFrame: ({ index, totalFrames, predictions }) => {
const percent = ((index / totalFrames) * 100).toFixed(0)
this.setState({
message: `${percent}% - Frame ${index} is ${predictions[0].className}`,
})
},
})
const deemedEvil = this.detectGifEvil(predictions)
// If any frame is NSFW, blur it (if blur is on)
const droppedImageStyle = this.detectBlurStatus(predictions)
const gifMessage =
deemedEvil > 0
? `Detected ${deemedEvil} NSFW frames`
: 'All frames look clean'
this.setState({
message: `GIF Result: ${gifMessage}`,
predictions,
droppedImageStyle,
loading: false,
})
} else {
const predictions = await this.state.model.classify(img)
let droppedImageStyle = this.detectBlurStatus(predictions)
this.setState({
message: `Identified as ${predictions[0].className}`,
predictions,
droppedImageStyle,
})
}
const predictions = await this.state.model.classify(img)
let droppedImageStyle = this.detectBlurStatus(predictions)
this.setState({
message: `Identified as ${predictions[0].className}`,
predictions,
droppedImageStyle,
})
}

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

onDrop = (accepted, rejected) => {
if (rejected.length > 0) {
window.alert('JPG, PNG, WEBP, GIF only plz')
window.alert('JPG, PNG, WEBP only plz')
} else {
let droppedImageStyle = this.state.blurNSFW ? blurred : clean
this.setState({
Expand Down Expand Up @@ -236,7 +188,6 @@ class App extends Component {
/>
)
} else {
// SuperGif kills our React Component
// Only way I can seem to revive it is
// to force a full re-render of Drop area
if (this.state.hardReset) {
Expand All @@ -246,7 +197,7 @@ class App extends Component {
return (
<Dropzone
id="dropBox"
accept="image/jpeg, image/png, image/gif, image/webp"
accept="image/jpeg, image/png, image/webp"
className="photo-box"
onDrop={this.onDrop.bind(this)}
>
Expand Down Expand Up @@ -299,7 +250,6 @@ class App extends Component {
<Loading showLoading={this.state.loading} />
<Results
message={this.state.message}
gifControl={this.state.gifControl}
predictions={this.state.predictions}
/>
</main>
Expand Down
106 changes: 0 additions & 106 deletions example/nsfw_demo/src/components/GifBar.js

This file was deleted.

5 changes: 1 addition & 4 deletions example/nsfw_demo/src/components/Results.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import React from 'react'
import GifBar from './GifBar'

// Render Text Prediction OR GifBar
// Render Text Prediction
const renderPredictions = props => {
// only render if predictions is in singular format
if (props.predictions[0] && props.predictions[0].className) {
Expand All @@ -17,8 +16,6 @@ const renderPredictions = props => {
</ul>
</div>
)
} else if (props.predictions[0]) {
return <GifBar data={props.predictions} gifControl={props.gifControl} />
}
}

Expand Down
Loading