Skip to content

Commit 04995d2

Browse files
Weak supervision running into error
1 parent 83b7626 commit 04995d2

File tree

4 files changed

+27
-5
lines changed

4 files changed

+27
-5
lines changed

src/components/projects/projectId/heuristics/HeuristicsHeader.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@ export default function HeuristicsHeader(props: HeuristicsHeaderProps) {
4444
const [currentWeakSupervisionRun, setCurrentWeakSupervisionRun] = useState(null);
4545
const [loadingIconWS, setLoadingIconWS] = useState(false);
4646

47-
4847
useEffect(() => {
4948
if (!heuristics) return;
5049
setAreHeuristicsSelected(checkSelectedHeuristics(heuristics, false));
@@ -201,7 +200,8 @@ export default function HeuristicsHeader(props: HeuristicsHeaderProps) {
201200
{areValidHeuristicsSelected ? (
202201
<Tooltip content={TOOLTIPS_DICT.HEURISTICS.WEAK_SUPERVISION} color="invert" placement="top">
203202
<button onClick={startWeakSupervision}
204-
className="bg-indigo-700 flex items-center text-white text-xs font-semibold mr-3 px-4 py-2 rounded-md border hover:bg-indigo-800 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-indigo-500">
203+
disabled={props.tokenizationProgress < 1}
204+
className="bg-indigo-700 flex items-center text-white text-xs font-semibold mr-3 px-4 py-2 rounded-md border hover:bg-indigo-800 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-indigo-500 disabled:opacity-50 disabled:cursor-not-allowed">
205205
Weak supervision
206206
</button>
207207
</Tooltip>

src/components/projects/projectId/heuristics/HeuristicsOverview.tsx

+23-2
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,10 @@ import { useWebsocket } from "@/submodules/react-components/hooks/web-socket/use
2020
import { getAllComments } from "@/src/services/base/comment";
2121
import { getAttributes } from "@/src/services/base/attribute";
2222
import { getInformationSourcesOverviewData } from "@/src/services/base/heuristic";
23-
import { getLabelingTasksByProjectId } from "@/src/services/base/project";
23+
import { getLabelingTasksByProjectId, getProjectTokenization } from "@/src/services/base/project";
2424
import { getEmbeddings } from "@/src/services/base/embedding";
2525
import { Application, CurrentPage } from "@/submodules/react-components/hooks/web-socket/constants";
26+
import { timer } from "rxjs";
2627

2728
export function HeuristicsOverview() {
2829
const dispatch = useDispatch();
@@ -33,12 +34,15 @@ export function HeuristicsOverview() {
3334
const attributes = useSelector(selectUsableNonTextAttributes);
3435
const allUsers = useSelector(selectAllUsers);
3536
const [filteredList, setFilteredList] = useState([]);
37+
const [tokenizationProgress, setTokenizationProgress] = useState(null);
38+
3639

3740
useEffect(() => {
3841
if (!projectId || !embeddings || !attributes) return;
3942
refetchLabelingTasksAndProcess();
4043
refetchHeuristicsAndProcess();
4144
refetchEmbeddingsAndProcess();
45+
checkProjectTokenization();
4246
if (attributes.length == 0) {
4347
getAttributes(projectId, ['ALL'], (res) => {
4448
dispatch(setAllAttributes(res.data['attributesByProjectId']));
@@ -91,6 +95,12 @@ export function HeuristicsOverview() {
9195
});
9296
}
9397

98+
function checkProjectTokenization() {
99+
getProjectTokenization(projectId, (res) => {
100+
setTokenizationProgress(res.data['projectTokenization']?.progress);
101+
});
102+
}
103+
94104
const handleWebsocketNotification = useCallback((msgParts: string[]) => {
95105
if (['labeling_task_updated', 'labeling_task_created'].includes(msgParts[1])) {
96106
refetchLabelingTasksAndProcess();
@@ -102,14 +112,25 @@ export function HeuristicsOverview() {
102112
} else if (msgParts[1] == 'embedding_deleted' || (msgParts[1] == 'embedding' && msgParts[3] == 'state')) {
103113
refetchEmbeddingsAndProcess();
104114
}
115+
116+
if (msgParts[1] == 'tokenization') {
117+
if (msgParts[3] == 'progress') {
118+
setTokenizationProgress(Number(msgParts[4]));
119+
} else if (msgParts[3] == 'state') {
120+
if (msgParts[4] == 'IN_PROGRESS') setTokenizationProgress(0);
121+
else if (msgParts[4] == 'FINISHED') {
122+
timer(5000).subscribe(() => checkProjectTokenization());
123+
}
124+
}
125+
}
105126
}, [projectId]);
106127

107128
const orgId = useSelector(selectOrganizationId);
108129
useWebsocket(orgId, Application.REFINERY, CurrentPage.HEURISTICS, handleWebsocketNotification, projectId);
109130

110131
return (projectId && <div className="p-4 bg-gray-100 h-full flex-1 flex flex-col">
111132
<div className="w-full h-full -mr-4">
112-
<HeuristicsHeader refetch={refetchHeuristicsAndProcess}
133+
<HeuristicsHeader refetch={refetchHeuristicsAndProcess} tokenizationProgress={tokenizationProgress}
113134
filterList={(labelingTask: LabelingTask) => setFilteredList(labelingTask != null ? heuristics.filter((heuristic) => heuristic.labelingTaskId === labelingTask.id) : heuristics)} />
114135

115136
{heuristics && heuristics.length == 0 ? (

src/types/components/projects/projectId/heuristics/heuristics.ts

+1
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ export type Color = {
6868
export type HeuristicsHeaderProps = {
6969
filterList: (labelingTask: LabelingTask) => void;
7070
refetch: () => void;
71+
tokenizationProgress: number;
7172
}
7273

7374
export type CurrentWeakSupervision = {

0 commit comments

Comments
 (0)