Skip to content

Commit

Permalink
Merge pull request #647 from AI4Bharat/audio-lsf-bugfix
Browse files Browse the repository at this point in the history
check for empty transcription in audio annotations
  • Loading branch information
aparna-aa authored Aug 10, 2023
2 parents bf8d7fd + 442edb1 commit 0236e0c
Show file tree
Hide file tree
Showing 2 changed files with 100 additions and 57 deletions.
152 changes: 97 additions & 55 deletions src/ui/pages/container/Label-Studio/LSF.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,17 +35,13 @@ import APITransport from "../../../../redux/actions/apitransport/apitransport";

import { useParams, useNavigate } from "react-router-dom";
import useFullPageLoader from "../../../../hooks/useFullPageLoader";
import { snakeToTitleCase } from "../../../../utils/utils";

import styles from "./lsf.module.css";
import "./lsf.css";
import { useDispatch, useSelector } from "react-redux";
import { translate } from "../../../../config/localisation";
import Glossary from "../Glossary/Glossary";
import { TabsSuggestionData } from "../../../../utils/TabsSuggestionData/TabsSuggestionData";
import InfoIcon from "@mui/icons-material/Info";
import getCaretCoordinates from "textarea-caret";
import CloseIcon from "@mui/icons-material/Close";

const filterAnnotations = (
annotations,
Expand All @@ -66,7 +62,7 @@ const filterAnnotations = (
);

if (userAnnotation) {

if (userAnnotation.annotation_status === "labeled") {
const superCheckedAnnotation = annotations.find(
(annotation) => annotation.annotation_type === 3
Expand All @@ -88,7 +84,7 @@ const filterAnnotations = (
);
setDisableBtns(true);
disable = true;
}else if (
} else if (
review &&
[
"skipped",
Expand Down Expand Up @@ -140,10 +136,10 @@ const filterAnnotations = (
setFilterMessage("Skip button is disabled, since the task is being reviewed");
}

else {
else {
filteredAnnotations = [userAnnotation];
}
} else if([4, 5, 6].includes(user.role)) {
} else if ([4, 5, 6].includes(user.role)) {
filteredAnnotations = annotations.filter((a) => a.annotation_type === 1);
disable = true;
setDisableBtns(true);
Expand All @@ -155,6 +151,10 @@ const filterAnnotations = (
//used just in postAnnotation to support draft status update.

const AUTO_SAVE_INTERVAL = 30000; //1 minute
const AUDIO_PROJECT_SAVE_CHECK = [
"AudioTranscription",
"AudioTranscriptionEditing",
];

const LabelStudioWrapper = ({
annotationNotesRef,
Expand Down Expand Up @@ -184,6 +184,7 @@ const LabelStudioWrapper = ({
const [annotations, setAnnotations] = useState([]);
const load_time = useRef();
const [autoSave, setAutoSave] = useState(true);
let isAudioProject = useRef();
const { projectId, taskId } = useParams();
const userData = useSelector((state) => state.fetchLoggedInUserData.data);
let loaded = useRef();
Expand Down Expand Up @@ -257,13 +258,14 @@ const LabelStudioWrapper = ({
) {
let interfaces = [];
if (predictions == null) predictions = [];
const [filteredAnnotations, disableLSFControls,disableSkip] = filterAnnotations(
const [filteredAnnotations, disableLSFControls, disableSkip] = filterAnnotations(
annotations,
userData,
setDisableBtns,
setFilterMessage,
setDisableButton
);
isAudioProject.current = AUDIO_PROJECT_SAVE_CHECK.includes(projectType);
//console.log("labelConfig", labelConfig);

if (taskData.task_status === "freezed") {
Expand All @@ -276,10 +278,7 @@ const LabelStudioWrapper = ({
"infobar",
"topbar",
"instruction",
...(projectType === "AudioTranscription" ||
projectType === "AudioTranscriptionEditing"
? ["side-column"]
: []),
...(isAudioProject.current ? ["side-column"] : []),
"annotations:history",
"annotations:tabs",
"annotations:menu",
Expand All @@ -297,7 +296,7 @@ const LabelStudioWrapper = ({
"panel",
"update",
"submit",
...(!disableSkip ?["skip"]:[]),
...(!disableSkip ? ["skip"] : []),
...(taskData?.annotation_users?.some(
(user) => user === userData.id && !disableLSFControls
)
Expand All @@ -306,10 +305,7 @@ const LabelStudioWrapper = ({
"infobar",
"topbar",
"instruction",
...(projectType === "AudioTranscription" ||
projectType === "AudioTranscriptionEditing"
? ["side-column"]
: []),
...(isAudioProject.current ? ["side-column"] : []),
"annotations:history",
"annotations:tabs",
"annotations:menu",
Expand All @@ -323,8 +319,7 @@ const LabelStudioWrapper = ({
"edit-history",
];
}

if(disableLSFControls || !taskData?.annotation_users?.some(
if (disableLSFControls || !taskData?.annotation_users?.some(
(user) => user === userData.id)) setAutoSave(false);

if (rootRef.current) {
Expand Down Expand Up @@ -362,7 +357,31 @@ const LabelStudioWrapper = ({
}
load_time.current = new Date();
},

onSubmitAnnotation: function (ls, annotation) {
if (isAudioProject.current) {
let temp = annotation.serializeAnnotation();
const counter = temp.reduce((acc, curr) => {
if (curr.from_name === "labels")
acc.labels++;
else if (curr.from_name === "transcribed_json") {
if (curr.value.text[0] === "")
acc.empty++;
acc.textareas++;
}
return acc;
},
{ labels: 0, textareas: 0, empty: 0 }
);
if (counter.labels !== counter.textareas || counter.empty) {
setSnackbarInfo({
open: true,
message: "Please fill the annotations for every segment/region",
variant: "warning",
});
return;
}
}
showLoader();
if (taskData.annotation_status !== "freezed") {
postAnnotation(
Expand Down Expand Up @@ -417,12 +436,35 @@ const LabelStudioWrapper = ({
},

onUpdateAnnotation: function (ls, annotation) {
if (isAudioProject.current) {
let temp = annotation.serializeAnnotation();
const counter = temp.reduce((acc, curr) => {
if (curr.from_name === "labels")
acc.labels++;
else if (curr.from_name === "transcribed_json") {
if (curr.value.text[0] === "")
acc.empty++;
acc.textareas++;
}
return acc;
},
{ labels: 0, textareas: 0, empty: 0 }
);
if (counter.labels !== counter.textareas || counter.empty) {
setSnackbarInfo({
open: true,
message: "Please fill the annotations for every segment/region",
variant: "warning",
});
return;
}
}
if (taskData.annotation_status !== "freezed") {
for (let i = 0; i < annotations.length; i++) {
if (
!annotations[i].result?.length || !annotation.serializeAnnotation().length ||
annotation.serializeAnnotation()[0].id ===
annotations[i].result[0].id
annotations[i].result[0].id
) {
setAutoSave(false);
showLoader();
Expand Down Expand Up @@ -500,8 +542,8 @@ const LabelStudioWrapper = ({
loaded.current = taskId;
getProjectsandTasks(projectId, taskId).then(
([labelConfig, taskData, annotations, predictions]) => {
if(annotations.message?.includes("not a part of this project") || annotations.detail?.includes("Not found")){
if(annotations.detail?.includes("Not found")) annotations.message = "Task not found";
if (annotations.message?.includes("not a part of this project") || annotations.detail?.includes("Not found")) {
if (annotations.detail?.includes("Not found")) annotations.message = "Task not found";
setSnackbarInfo({
open: true,
message: annotations.message,
Expand All @@ -514,11 +556,11 @@ const LabelStudioWrapper = ({
// console.log("[labelConfig, taskData, annotations, predictions]", [labelConfig, taskData, annotations, predictions]);
let tempLabelConfig =
labelConfig.project_type === "ConversationTranslation" ||
labelConfig.project_type === "ConversationTranslationEditing"
labelConfig.project_type === "ConversationTranslationEditing"
? generateLabelConfig(taskData.data)
: labelConfig.project_type === "ConversationVerification"
? conversationVerificationLabelConfig(taskData.data)
: labelConfig.label_config;
? conversationVerificationLabelConfig(taskData.data)
: labelConfig.label_config;
setAnnotations(annotations);
setLabelConfig(tempLabelConfig);
setTaskData(taskData);
Expand Down Expand Up @@ -664,41 +706,41 @@ const LabelStudioWrapper = ({
}, [taskId]);

const autoSaveAnnotation = () => {
if(autoSave && lsfRef.current?.store?.annotationStore?.selected) {
if(taskData?.annotation_status !== "freezed") {
if (autoSave && lsfRef.current?.store?.annotationStore?.selected) {
if (taskData?.annotation_status !== "freezed") {
let annotation = lsfRef.current.store.annotationStore.selected;
for (let i = 0; i < annotations.length; i++) {
if (
!annotations[i].result?.length ||
annotation.serializeAnnotation()[0].id ===
annotations[i].result[0].id
annotations[i].result[0].id
) {
let temp = annotation.serializeAnnotation();
if(annotations[i].annotation_type !== 1) continue;
for (let i = 0; i < temp.length; i++) {
if (temp[i].value.text) {
temp[i].value.text = [temp[i].value.text[0]];
}
let temp = annotation.serializeAnnotation();
if (annotations[i].annotation_type !== 1) continue;
for (let i = 0; i < temp.length; i++) {
if (temp[i].value.text) {
temp[i].value.text = [temp[i].value.text[0]];
}
patchAnnotation(
temp,
annotations[i].id,
load_time.current,
annotations[i].lead_time,
annotations[i].annotation_status,
annotationNotesRef.current.value,
true
).then((res) => {
if (res.status !== 200) {
setSnackbarInfo({
open: true,
message: "Error in autosaving annotation",
variant: "error",
});
}
});
}
patchAnnotation(
temp,
annotations[i].id,
load_time.current,
annotations[i].lead_time,
annotations[i].annotation_status,
annotationNotesRef.current.value,
true
).then((res) => {
if (res.status !== 200) {
setSnackbarInfo({
open: true,
message: "Error in autosaving annotation",
variant: "error",
});
}
});
}
}
} else
setSnackbarInfo({
open: true,
Expand Down Expand Up @@ -726,7 +768,7 @@ const LabelStudioWrapper = ({
const handleVisibilityChange = () => setVisibile(!document[hidden]);
document.addEventListener(visibilityChange, handleVisibilityChange);
return () => {
document.removeEventListener(visibilityChange, handleVisibilityChange);
document.removeEventListener(visibilityChange, handleVisibilityChange);
}
}, []);

Expand All @@ -737,7 +779,7 @@ const LabelStudioWrapper = ({
useEffect(() => {
const interval = setInterval(() => {
visible && autoSaveAnnotation();
}, AUTO_SAVE_INTERVAL);
}, AUTO_SAVE_INTERVAL);
return () => clearInterval(interval);
}, [visible, autoSave, lsfRef.current?.store?.annotationStore?.selected, taskData]);

Expand Down Expand Up @@ -979,7 +1021,7 @@ export default function LSF() {
reviewNotesRef.current?.value !== "" ? "success" : "primary"
}
onClick={handleCollapseClick}
// style={{ marginBottom: "20px" }}
// style={{ marginBottom: "20px" }}
>
Notes {reviewNotesRef.current?.value !== "" && "*"}
</Button>
Expand Down
5 changes: 3 additions & 2 deletions src/ui/pages/container/UserManagement/ScheduleMails.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ const ScheduleMails = () => {
};

const createScheduledMail = () => {
if (!reportLevel || !schedule || !selectedProjectType || (reportLevel == 2 && workspaceId == 0)) {
if (!reportLevel || !schedule || !selectedProjectType || (reportLevel === 2 && workspaceId === 0)) {
setSnackbarState({
open: true,
message: "Invalid input",
Expand Down Expand Up @@ -154,6 +154,7 @@ const ScheduleMails = () => {
onClick={() => deleteScheduledMail(mail)} />
</Box>
);
return mail;
});
setColumns(tempColumns);
setTableData(scheduledMails);
Expand Down Expand Up @@ -228,7 +229,7 @@ const ScheduleMails = () => {
label="Report Level"
onChange={(e) => setReportLevel(e.target.value)}
>
{userRole.OrganizationOwner === userDetails?.role || userRole.Admin === userDetails?.role &&
{(userRole.OrganizationOwner === userDetails?.role || userRole.Admin === userDetails?.role) &&
<MenuItem value={1}>Organization</MenuItem>
}
<MenuItem value={2}>Workspace</MenuItem>
Expand Down

0 comments on commit 0236e0c

Please sign in to comment.