An open API service indexing awesome lists of open source software.

https://github.com/aralroca/react-text-toxicity

Detect text toxicity in a simple way, using React. Based in a Keras model, loaded with Tensorflow.js.
https://github.com/aralroca/react-text-toxicity

javascript machine-learning preact react tensorflow text toxicity

Last synced: about 2 months ago
JSON representation

Detect text toxicity in a simple way, using React. Based in a Keras model, loaded with Tensorflow.js.

Awesome Lists containing this project

README

        

## React Text Toxicity

Detect toxicity in text using React.

It's based on this model: https://github.com/tensorflow/tfjs-models/tree/master/toxicity

## Getting started

```
yarn add react-text-toxicity
```

Import as:

```js
import useTextToxicity from "react-text-toxicity";
```

Use it as:

```js
const predictions = useTextToxicity('text', { threshold, delay });
```

* **text** - Text to predict
* **options**
* **threshold** Prediction threshold *(0.9 as default)*
* **delay** Delay in milliseconds applied to debounce multiple changes *(300ms as default)*

## Example

![example](./example/toxicity.gif)

```jsx
import React, { Fragment, useState } from "react";
import useTextToxicity from "react-text-toxicity";

function Toxicity({ predictions }) {
const style = { margin: 10 };

if (!predictions) return

Loading predictions...
;

return (


{predictions.map(({ label, match, probability }) => (

{`${label} - ${probability} - ${match ? "🤢" : "🥰"}`}

))}

);
}

export default function Index() {
const [value, setValue] = useState("");
const predictions = useTextToxicity(value);

return (



Write something

setValue(e.target.value)}
/>

{value && }

);
}
```