From ae65aa34bf6358fea2c4227a3e5c6c20b47453e4 Mon Sep 17 00:00:00 2001 From: Pursottam6003 Date: Sun, 16 Jun 2024 17:14:19 +0530 Subject: [PATCH 1/6] added the implemented frontend for contextual-transliteration source --- src/redux/actions/api/LSFAPI/LSFAPI.js | 42 ++++++++++++ src/ui/pages/container/Label-Studio/LSF.jsx | 75 ++++++++++++++++++++- 2 files changed, 116 insertions(+), 1 deletion(-) diff --git a/src/redux/actions/api/LSFAPI/LSFAPI.js b/src/redux/actions/api/LSFAPI/LSFAPI.js index fadef9d6..a024c765 100644 --- a/src/redux/actions/api/LSFAPI/LSFAPI.js +++ b/src/redux/actions/api/LSFAPI/LSFAPI.js @@ -36,6 +36,47 @@ const fetchAnnotation = async (taskID) => { } }; + +const fetchTransliteration = async (sourceText,srcLng,tgtLng) => { + const url = 'https://api.dhruva.ekstep.ai/services/inference/transliteration'; + const payload = { + input: [ + { + source: sourceText, + }, + ], + config: { + serviceId: 'ai4bharat/indicxlit--gpu-t4', + language: { + sourceLanguage: srcLng, + sourceScriptCode: '', + targetLanguage: tgtLng, + targetScriptCode: '', + }, + isSentence: true, + numSuggestions: 0, + }, + controlConfig: { + dataTracking: true, + }, + }; + + const response = await fetch(url, { + method: 'POST', + headers: { + 'Content-Type': 'application/json', + Authorization: 'uOQOvZAkdKQpaeZa5-K03k9SIXOtZFEIkdj995-lTz_bozcijCNgVye2jEGIRFQG', + }, + body: JSON.stringify(payload), + }); + + if (!response.ok) { + throw new Error(`HTTP error! status: ${response.status}`); + } + const data = await response.json(); + return data; +}; + const postAnnotation = async ( result, task, @@ -273,6 +314,7 @@ export { patchAnnotation, deleteAnnotation, fetchAnnotation, + fetchTransliteration, postReview, patchReview, patchSuperChecker, diff --git a/src/ui/pages/container/Label-Studio/LSF.jsx b/src/ui/pages/container/Label-Studio/LSF.jsx index 779f31ae..37bc9b58 100644 --- a/src/ui/pages/container/Label-Studio/LSF.jsx +++ b/src/ui/pages/container/Label-Studio/LSF.jsx @@ -34,6 +34,7 @@ import { patchAnnotation, deleteAnnotation, fetchAnnotation, + fetchTransliteration, } from "../../../../redux/actions/api/LSFAPI/LSFAPI"; import GetProjectDetailsAPI from "../../../../redux/actions/api/ProjectDetails/GetProjectDetails"; import APITransport from "../../../../redux/actions/apitransport/apitransport"; @@ -51,6 +52,11 @@ import InfoOutlinedIcon from "@mui/icons-material/InfoOutlined"; import getTaskAssignedUsers from "../../../../utils/getTaskAssignedUsers"; import LightTooltip from "../../component/common/Tooltip"; import { labelConfigJS } from "./labelConfigJSX"; +import DatasetStyle from "../../../styles/Dataset"; +import { set } from "date-fns"; +import CustomButton from "../../component/common/Button"; +import CircularProgress from '@mui/material/CircularProgress'; +import LanguageCode from "../../../../utils/LanguageCode"; const filterAnnotations = ( annotations, @@ -206,7 +212,9 @@ const LabelStudioWrapper = ({ const [filterMessage, setFilterMessage] = useState(null); const [disableButton, setDisableButton] = useState(false); const [assignedUsers, setAssignedUsers] = useState(null); - //console.log("projectId, taskId", projectId, taskId); + const [translitrationData, setTransliterationData] = useState([]); + const [showSpinner , setShowSpinner] = useState(false); + //console.log("projectId, taskId", projectId, taskId); // debugger // const projectType = ProjectDetails?.project_type?.includes("Audio") @@ -553,6 +561,12 @@ const LabelStudioWrapper = ({ temp[i].value.text = [temp[i].value.text[0]]; } } + setSnackbarInfo({ + open: true, + message: "Please click on Check Transliteration button first", + variant: "info", + }); + patchAnnotation( taskId, temp, @@ -966,6 +980,36 @@ const LabelStudioWrapper = ({ }); }; + const handleTranslitrationOnClick = async () => { + setShowSpinner(true) + const language = LanguageCode.languages + let input_lng_code = '' + let output_lng_code = '' + + language.filter((lang) => { + if(lang.label === taskData?.data?.input_language){ + input_lng_code= lang.code + } + if(lang.label === taskData?.data?.output_language){ + output_lng_code = lang.code + } + }) + const res = await fetchTransliteration(taskData?.data?.input_text,input_lng_code, output_lng_code); + if(res && res?.output) { + setTransliterationData(res); + setSnackbarInfo({ + open: true, + message: "Transliteration Done", + variant: "success", + }); + setShowSpinner(false) + } + } + + + + + const renderSnackBar = () => { return ( {tagSuggestionList} + + {!loader&& ProjectDetails?.project_type?.includes("ContextualTranslationEditing") && + + + } + onClick={handleTranslitrationOnClick} + label="Check Transliteration" + disabled={showSpinner} + /> + + + {translitrationData?.output && + +