Skip to content

Commit

Permalink
Merge pull request #915 from AI4Bharat/develop
Browse files Browse the repository at this point in the history
Develop to wavesurfer
  • Loading branch information
kartikvirendrar authored Feb 13, 2024
2 parents 9d255df + 034df6a commit edce66e
Show file tree
Hide file tree
Showing 16 changed files with 64 additions and 33 deletions.
4 changes: 2 additions & 2 deletions src/config/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ const configs = {
BASE_URL: "https://backend.prod2.shoonya.ai4bharat.org",
BASE_URL_AUTO: process.env.REACT_APP_APIGW_BASE_URL
? process.env.REACT_APP_APIGW_BASE_URL
:"https://backend.dev.shoonya.ai4bharat.org"
:"https://backend.dev.shoonya.ai4bharat.org"
};

export default configs;
//http://20.51.211.111:8000
//https://backend.shoonya.ai4bharat.org/
// https://backend.dev2.shoonya.ai4bharat.org
//https://backend.prod2.shoonya.ai4bharat.org
//https://backend.prod2.shoonya.ai4bharat.org
6 changes: 6 additions & 0 deletions src/redux/actions/api/LSFAPI/LSFAPI.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ const postReview = async (


const patchAnnotation = async (
taskId,
result,
annotationID,
load_time,
Expand All @@ -113,6 +114,7 @@ const patchAnnotation = async (
lead_time: (new Date() - load_time) / 1000 + Number(lead_time ?? 0),
annotation_status: annotation_status,
}),
task_id: taskId,
annotation_notes: notes,
...(autoSave && { auto_save: true }),
});
Expand All @@ -123,6 +125,7 @@ const patchAnnotation = async (
};

const patchReview = async (
taskId,
annotationID,
load_time,
lead_time,
Expand All @@ -137,6 +140,7 @@ const patchReview = async (
lead_time: (new Date() - load_time) / 1000 + Number(lead_time ?? 0),
annotation_status: review_status,
result: result,
task_id: taskId,
review_notes: reviewnotes,
...((review_status === "to_be_revised" ||
review_status === "accepted" ||
Expand All @@ -162,6 +166,7 @@ const patchReview = async (


const patchSuperChecker = async (
taskId,
annotationID,
load_time,
lead_time,
Expand All @@ -176,6 +181,7 @@ const patchSuperChecker = async (
await axiosInstance.patch(`/annotation/${annotationID}/`, {
lead_time: (new Date() - load_time) / 1000 + Number(lead_time ?? 0),
annotation_status: review_status,
task_id: taskId,
result: result,
parent_annotation: parentAnnotation,
supercheck_notes: superchecknotes,
Expand Down
4 changes: 2 additions & 2 deletions src/redux/actions/api/ProjectDetails/DownloadCSVProject.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@
import constants from "../../../constants";

export default class DownloadProjectCsvAPI extends API {
constructor(projectId,taskStatus, downloadMetadataToggle=false,timeout = 2000) {
constructor(projectId,taskStatus,timeout = 2000) {
super("POST", timeout, false);
this.projectBody={}//object with key-value pair
this.type = constants.DOWNLOAD_PROJECT_CSV;
this.endpoint = `${super.apiEndPointAuto()}${ENDPOINTS.getProjects}${projectId}/download/?export_type=CSV&task_status=${taskStatus}&include_input_data_metadata_json=${downloadMetadataToggle}`;
this.endpoint = `${super.apiEndPointAuto()}${ENDPOINTS.getProjects}${projectId}/download/?export_type=CSV&task_status=${taskStatus}`;
}

processResponse(res) {
Expand Down
4 changes: 2 additions & 2 deletions src/redux/actions/api/ProjectDetails/DownloadJSONProject.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@
import constants from "../../../constants";

export default class DownloadProjectJSONAPI extends API {
constructor(projectId, taskStatus ,downloadMetadataToggle=false, timeout = 2000) {
constructor(projectId, taskStatus , timeout = 2000) {
super("POST", timeout, false);
this.projectBody={}//object with key-value pair
this.type = constants.DOWNLOAD_PROJECT_JSON;
this.endpoint = `${super.apiEndPointAuto()}${ENDPOINTS.getProjects}${projectId}/download/?export_type=JSON&task_status=${taskStatus}&include_input_data_metadata_json=${downloadMetadataToggle}`;
this.endpoint = `${super.apiEndPointAuto()}${ENDPOINTS.getProjects}${projectId}/download/?export_type=JSON&task_status=${taskStatus}`;
}

processResponse(res) {
Expand Down
4 changes: 2 additions & 2 deletions src/redux/actions/api/ProjectDetails/DownloadTSVProject.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@
import constants from "../../../constants";

export default class DownloadProjectTsvAPI extends API {
constructor(projectId,taskStatus,downloadMetadataToggle=false, timeout = 2000) {
constructor(projectId,taskStatus, timeout = 2000) {
super("POST", timeout, false);
this.type = constants.DOWNLOAD_PROJECT_TSV;
this.projectBody={}//object with key-value pair
this.endpoint = `${super.apiEndPointAuto()}${ENDPOINTS.getProjects}${projectId}/download/?export_type=TSV&task_status=${taskStatus}&include_input_data_metadata_json=${downloadMetadataToggle}`;
this.endpoint = `${super.apiEndPointAuto()}${ENDPOINTS.getProjects}${projectId}/download/?export_type=TSV&task_status=${taskStatus}`;
}

processResponse(res) {
Expand Down
4 changes: 2 additions & 2 deletions src/ui/pages/component/Tabs/AdvancedOperation.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -699,7 +699,7 @@ const AdvancedOperation = (props) => {
sx={{ mt: 1 }}
>
{/* <div className={classes.divider} ></div> */}
<Grid item xs={12} sm={12} md={12} lg={12} xl={12}>
{/* <Grid item xs={12} sm={12} md={12} lg={12} xl={12}>
<FormControlLabel
control={<Switch color="primary" />}
label="Download Metadata"
Expand All @@ -709,7 +709,7 @@ const AdvancedOperation = (props) => {
disabled ={userRole.WorkspaceManager === loggedInUserData?.role?true:false}
/>
</Grid>
</Grid> */}
</Grid>

<Dialog
Expand Down
11 changes: 0 additions & 11 deletions src/ui/pages/component/common/Header.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -446,17 +446,6 @@ console.log(unseenNotifications,'uuu');
Projects
</NavLink>
</Typography>
<Typography variant="body1">
<NavLink
to="/datasets"
className={({ isActive }) =>
isActive ? classes.highlightedMenu : classes.headerMenu
}
activeClassName={classes.highlightedMenu}
>
Datasets
</NavLink>
</Typography>
<Typography variant="body1">
<NavLink
to="/analytics"
Expand Down
9 changes: 9 additions & 0 deletions src/ui/pages/container/CL-Transcription/AudioPanel.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,20 @@ const AudioPanel = memo( ({
// }, [$video]);

//console.log(TaskDetails?.data?.audio_url,"TaskDetailsTaskDetailsTaskDetails")

useEffect(() => {
const audio = document.getElementById('audio-panel');
audio.oncontextmenu = function (e) {
e.preventDefault();
};
}, [])

return (
<Grid style={{ padding: "0px 20px 0px 20px" }}>

{/* <div className={classes.videoPlayerParent} style={{ display: "flex" }}> */}
<audio
id ="audio-panel"
controls
controlsList="nodownload"
src={TaskDetails?.data?.audio_url}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -591,6 +591,7 @@ const AudioTranscriptionLandingPage = () => {
setLoading(true);
setAutoSave(false);
const PatchAPIdata = {
task_id: taskId,
annotation_status: value,
annotation_notes: JSON.stringify(annotationNotesRef.current.getEditor().getContents()),
lead_time:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -614,6 +614,7 @@ const ReviewAudioTranscriptionLandingPage = () => {
setLoading(true);
setAutoSave(false);
const PatchAPIdata = {
task_id: taskId,
annotation_status: value,
review_notes: JSON.stringify(reviewNotesRef.current.getEditor().getContents()),
lead_time:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -536,6 +536,7 @@ const SuperCheckerAudioTranscriptionLandingPage = () => {
setLoading(true);
setAutoSave(false);
const PatchAPIdata = {
task_id: taskId,
annotation_status: value,
supercheck_notes: JSON.stringify(superCheckerNotesRef.current.getEditor().getContents()),
lead_time:
Expand Down
35 changes: 25 additions & 10 deletions src/ui/pages/container/CL-Transcription/wavesurfer.jsx
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
import AudioTranscriptionLandingStyle from "../../../styles/AudioTranscriptionLandingStyle";
import { useEffect, useRef, memo, useState } from "react";
import { Box } from "@mui/material";
import { useEffect, useRef, memo, useState, useCallback } from "react";
import WaveSurfer from "wavesurfer.js";
import RegionsPlugin from "../../../../../node_modules/wavesurfer.js/dist/plugins/regions.esm.js";
import Minimap from "../../../../../node_modules/wavesurfer.js/dist/plugins/minimap.esm.js";
import TimelinePlugin from '../../../../../node_modules/wavesurfer.js/dist/plugins/timeline.esm.js';
import { useSelector } from "react-redux";
import { useSelector, useDispatch } from "react-redux";
import { setSubtitles } from "../../../../redux/actions/Common";
import C from "../../../../redux/constants";
import DT from "duration-time-conversion";

const Timeline2 = ({ details, waveformSettings }) => {
const $footer = useRef();
const classes = AudioTranscriptionLandingStyle();
const waveSurf = useRef(null);
const regions = useRef(null);
const result = useSelector((state) => state.commonReducer?.subtitles);
const player = useSelector((state) => state.commonReducer?.player);
const [currentSubs, setCurrentSubs] = useState([]);
console.log(result);
const dispatch = useDispatch();

useEffect(() => {
if (result) {
Expand Down Expand Up @@ -89,7 +89,6 @@ const Timeline2 = ({ details, waveformSettings }) => {
regions.current = waveSurf.current.registerPlugin(RegionsPlugin.create());
if (currentSubs){
waveSurf.current.on('decode', () => {
{
currentSubs?.map((sub, key) => {
regions.current.addRegion({
start: sub.startTime,
Expand All @@ -99,7 +98,6 @@ const Timeline2 = ({ details, waveformSettings }) => {
resize: true,
})
})
}
})
}
}
Expand All @@ -110,11 +108,13 @@ const Timeline2 = ({ details, waveformSettings }) => {
regions.current.clearRegions();
currentSubs?.map((sub, key) => {
regions.current.addRegion({
id: sub.id,
start: sub.startTime,
end: sub.endTime,
content: sub.text,
drag: false,
resize: true,
contentEditable: true,
color: sub.speaker_id === "Speaker 1"
? "rgb(0, 87, 158, 0.2)"
: sub.speaker_id === "Speaker 0"
Expand All @@ -123,7 +123,7 @@ const Timeline2 = ({ details, waveformSettings }) => {
})
})
}
}, [details, waveSurf.current, currentSubs])
}, [details, currentSubs])

if (waveSurf !== null && regions.current !== null) {
let activeRegion = null
Expand All @@ -143,6 +143,21 @@ const Timeline2 = ({ details, waveformSettings }) => {
})
}

const updateSub = useCallback((currentSubsCopy) => {
dispatch(setSubtitles(currentSubsCopy, C.SUBTITLES));
}, [dispatch]);

if (waveSurf !== null && regions.current !== null) {
regions.current.on('region-updated', (region) => {
let currentSubsCopy = currentSubs;
currentSubsCopy[region.id -1].text = region?.content?.innerHTML;
currentSubsCopy[region.id -1].start_time = DT.d2t(region.start);
currentSubsCopy[region.id -1].end_time = DT.d2t(region.end);
updateSub(currentSubsCopy);
player.play();
})
}

return (
<>
<div style={{ paddingLeft: "20px", paddingRight: "20px" }} id="waveform"></div>
Expand Down
5 changes: 4 additions & 1 deletion src/ui/pages/container/Label-Studio/LSF.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -456,6 +456,7 @@ const LabelStudioWrapper = ({
if (annotation) {
showLoader();
patchAnnotation(
taskId,
null,
annotation.id,
load_time.current,
Expand All @@ -482,7 +483,7 @@ const LabelStudioWrapper = ({
countLables++;
}
});
if (ids.size>countLables) {
if (projectType.includes("OCR") && ids.size>countLables) {
setSnackbarInfo({
open: true,
message: "Please select labels for all boxes",
Expand Down Expand Up @@ -528,6 +529,7 @@ const LabelStudioWrapper = ({
}
}
patchAnnotation(
taskId,
temp,
annotations[i].id,
load_time.current,
Expand Down Expand Up @@ -781,6 +783,7 @@ const LabelStudioWrapper = ({
}
}
patchAnnotation(
taskId,
temp,
annotations[i].id,
load_time.current,
Expand Down
3 changes: 3 additions & 0 deletions src/ui/pages/container/Label-Studio/ReviewLSF.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -452,6 +452,7 @@ const LabelStudioWrapper = ({
if (review) {
showLoader();
patchReview(
taskId,
review.id,
load_time.current,
review.lead_time,
Expand Down Expand Up @@ -613,6 +614,7 @@ const LabelStudioWrapper = ({
(annotation) => annotation.annotation_type === 2
)[0];
patchReview(
taskId,
review.id,
load_time.current,
review.lead_time,
Expand Down Expand Up @@ -1001,6 +1003,7 @@ const LabelStudioWrapper = ({
(annotation) => annotation.annotation_type === 2
)[0];
patchReview(
taskId,
review.id,
load_time.current,
review.lead_time,
Expand Down
3 changes: 3 additions & 0 deletions src/ui/pages/container/Label-Studio/SuperCheckerLSF.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -363,6 +363,7 @@ const LabelStudioWrapper = ({
if (review) {
showLoader();
patchSuperChecker(
taskId,
review.id,
load_time.current,
review.lead_time,
Expand Down Expand Up @@ -436,6 +437,7 @@ const LabelStudioWrapper = ({
)[0];

patchSuperChecker(
taskId,
superChecker.id,
load_time.current,
superChecker.lead_time,
Expand Down Expand Up @@ -716,6 +718,7 @@ const LabelStudioWrapper = ({
(value) => value.annotation_type === 3
)[0];
patchSuperChecker(
taskId,
superChecker.id,
load_time.current,
superChecker.lead_time,
Expand Down
2 changes: 1 addition & 1 deletion src/utils/TabsSuggestionData/TabsSuggestionData.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit edce66e

Please sign in to comment.