UNPKG

globalbridge-lsf-custom

Version:

GlobalBridge in-house labeling tool, originating from LSF.

150 lines (140 loc) • 3.63 kB
import React, { useEffect, useRef } from 'react'; import ReactDOM from 'react-dom'; import { Route, BrowserRouter as Router, Routes } from 'react-router-dom'; import './assets/styles/global.scss'; import { LabelStudio } from './LabelStudio.js'; import './core/feature-flags'; const lsfConfig = { description: 'Description', config: ` <View> <Header value="Label the image with polygons"/> <View style="top: 0"> <RectangleLabels name="tag" toName="img"> <Label value="Car"></Label> <Label value="Plane" background="#aa00ff"></Label> </RectangleLabels> </View> <Image name="img" value="$image" zoom="true"></Image> </View> `, interfaces: [ 'panel', 'update', 'submit', 'skip', 'controls', // "review", 'infobar', 'topbar', 'instruction', 'side-column', // "ground-truth", // "annotations:tabs", // "annotations:menu", // "annotations:current",` // "annotations:add-new", // "annotations:delete", // 'annotations:view-all', // "predictions:tabs", // "predictions:menu", // "auto-annotation", 'edit-history', 'topbar:prevnext', ], user: { 'id': 1, 'first_name': 'Nick', 'last_name': 'Skriabin', 'username': 'nick', 'email': 'nick@heartex.ai', 'avatar': null, 'initials': 'ni', }, users: [ { 'id': 1, 'first_name': 'Nick', 'last_name': 'Skriabin', 'username': 'nick', 'email': 'nick@heartex.ai', 'avatar': null, 'initials': 'ni', }, ], task: { // annotations: [], // predictions: [], // id: 1, data: { image: 'https://htx-misc.s3.amazonaws.com/opensource/label-studio/examples/images/nick-owuor-astro-nic-visuals-wDifg5xc9Z4-unsplash.jpg', }, }, // task: [ // { // "id": 1, // "data": { // "image": "https://images.unsplash.com/photo-1595433707802-6b2626ef1c91" // } // }, // { // "id": 2, // "data": { // "image": "https://images.unsplash.com/photo-1591871937573-74dbba515c4c" // } // }, // { // "id": 3, // "data": { // "image": "https://images.unsplash.com/photo-1593288942460-e321b92a6cde" // } // } // ], }; const RootComponent = ({ userConfig, classNameInput, }) => { const labelStudioRef = useRef(); useEffect(() => { labelStudioRef.current = new LabelStudio('label-studio', userConfig); labelStudioRef.current.on('labelStudioLoad', (LS) => { // Perform an action when Label Studio is loaded const c = LS.annotationStore.addAnnotation({ userGenerate: true, }); LS.annotationStore.selectAnnotation(c.id); }); labelStudioRef.current.on('submitAnnotation', (LS, annotation) => { // Retrieve an annotation in JSON format console.log(annotation.serializeAnnotation()); }); }, []); return ( <div id="ls-container"> <div id="label-studio" ref={labelStudioRef} className={classNameInput} /> </div> ); }; const App = () => ( <Router> <Routes> <Route path="/" element={( <RootComponent userConfig={lsfConfig} /> )} /> </Routes> </Router> ); ReactDOM.render( <App />, document.getElementById('root'), );