import { Configuration, DefaultApi, RobertaEmotionResponse, RobertaHateResponse, RobertaIronyResponse, RobertaOffensiveResponse, RobertaSentimentResponse } from "../service/openapi"; import {Button, Card, Col, Container, Form, FormControl, FormGroup, Row, Table} from "react-bootstrap"; import styles from "../styles/TextInput.module.scss"; import {createRef, FormEvent, forwardRef, useCallback, useEffect, useState} from "react"; import _ from "lodash"; let debounce = _.debounce(async (fn) => await fn(), 400) export default function TextInput(props) { const [text, setText] = useState(""); const [emotions, setEmotions] = useState(undefined); const [hate, setHate] = useState(undefined); const [irony, setIrony] = useState(undefined); const [offensive, setOffensive] = useState(undefined); const [sentiment, setSentiment] = useState(undefined); useEffect(() => { debounce(async () => { props.textFn(text); await evaluateInput(); }) }, [text]) const configuration = new Configuration({ basePath: 'http://localhost:8000' }); const api = new DefaultApi(configuration); let evaluateInput = async () => { if(!text) { setEmotions(undefined); setHate(undefined); setIrony(undefined); setOffensive(undefined); setSentiment(undefined); return; } try{ const [emotions, hate, irony, offensive, sentiment] = await Promise.all([ api.getEmotionsRobertaEmotionGet({text: text}), api.getHateRobertaHateGet({ text: text }), api.getIronyRobertaIronyGet({ text: text }), api.getOffensiveRobertaOffensiveGet({ text: text }), api.getSentimentRobertaSentimentGet({ text: text }) ]) setEmotions(emotions); setHate(hate); setIrony(irony); setOffensive(offensive); setSentiment(sentiment); } catch(error) { console.error(error) } } return ( <>

ALAS

setText(e.target.value)} className={styles.textBox} as="textarea" />

Analysis

Emotion
Joy {emotions?.joy.toFixed(3)}
Sadness {emotions?.sadness.toFixed(3)}
Anger {emotions?.anger.toFixed(3)}
Optimism {emotions?.optimism.toFixed(3)}
Temper
Hate {hate?.hate.toFixed(3)}
Irony {irony?.irony.toFixed(3)}
Offense {offensive?.offensive.toFixed(3)}
Sentiment
Negative {sentiment?.negative.toFixed(3)}
Neutral {sentiment?.neutral.toFixed(3)}
Positive {sentiment?.positive.toFixed(3)}
) }