Socket
Socket
Sign inDemoInstall

ai-lab

Package Overview
Dependencies
56
Maintainers
2
Versions
7
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 0.0.2-alpha.0 to 0.0.2-alpha.1

2

dist/ai-lab.cjs.production.min.js

@@ -1,2 +0,2 @@

"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e,t=require("react"),r=(e=t)&&"object"==typeof e&&"default"in e?e.default:e,n=require("@tensorflow/tfjs");function o(e,t,r,n,o,a,i){try{var s=e[a](i),c=s.value}catch(e){return void r(e)}s.done?t(c):Promise.resolve(c).then(n,o)}function a(e){return function(){var t=this,r=arguments;return new Promise((function(n,a){var i=e.apply(t,r);function s(e){o(i,n,a,s,c,"next",e)}function c(e){o(i,n,a,s,c,"throw",e)}s(void 0)}))}}function i(){return(i=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var r=arguments[t];for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&(e[n]=r[n])}return e}).apply(this,arguments)}function s(e,t){(null==t||t>e.length)&&(t=e.length);for(var r=0,n=new Array(t);r<t;r++)n[r]=e[r];return n}function c(e,t){var r="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(r)return(r=r.call(e)).next.bind(r);if(Array.isArray(e)||(r=function(e,t){if(e){if("string"==typeof e)return s(e,void 0);var r=Object.prototype.toString.call(e).slice(8,-1);return"Object"===r&&e.constructor&&(r=e.constructor.name),"Map"===r||"Set"===r?Array.from(e):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?s(e,void 0):void 0}}(e))||t&&e&&"number"==typeof e.length){r&&(e=r);var n=0;return function(){return n>=e.length?{done:!0}:{done:!1,value:e[n++]}}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}function u(e,t){return e(t={exports:{}},t.exports),t.exports}var l=u((function(e){var t=function(e){var t=Object.prototype,r=t.hasOwnProperty,n="function"==typeof Symbol?Symbol:{},o=n.iterator||"@@iterator",a=n.asyncIterator||"@@asyncIterator",i=n.toStringTag||"@@toStringTag";function s(e,t,r){return Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}),e[t]}try{s({},"")}catch(e){s=function(e,t,r){return e[t]=r}}function c(e,t,r,n){var o=Object.create((t&&t.prototype instanceof f?t:f).prototype),a=new E(n||[]);return o._invoke=function(e,t,r){var n="suspendedStart";return function(o,a){if("executing"===n)throw new Error("Generator is already running");if("completed"===n){if("throw"===o)throw a;return{value:void 0,done:!0}}for(r.method=o,r.arg=a;;){var i=r.delegate;if(i){var s=g(i,r);if(s){if(s===l)continue;return s}}if("next"===r.method)r.sent=r._sent=r.arg;else if("throw"===r.method){if("suspendedStart"===n)throw n="completed",r.arg;r.dispatchException(r.arg)}else"return"===r.method&&r.abrupt("return",r.arg);n="executing";var c=u(e,t,r);if("normal"===c.type){if(n=r.done?"completed":"suspendedYield",c.arg===l)continue;return{value:c.arg,done:r.done}}"throw"===c.type&&(n="completed",r.method="throw",r.arg=c.arg)}}}(e,r,a),o}function u(e,t,r){try{return{type:"normal",arg:e.call(t,r)}}catch(e){return{type:"throw",arg:e}}}e.wrap=c;var l={};function f(){}function p(){}function d(){}var h={};s(h,o,(function(){return this}));var v=Object.getPrototypeOf,m=v&&v(v(S([])));m&&m!==t&&r.call(m,o)&&(h=m);var y=d.prototype=f.prototype=Object.create(h);function x(e){["next","throw","return"].forEach((function(t){s(e,t,(function(e){return this._invoke(t,e)}))}))}function b(e,t){var n;this._invoke=function(o,a){function i(){return new t((function(n,i){!function n(o,a,i,s){var c=u(e[o],e,a);if("throw"!==c.type){var l=c.arg,f=l.value;return f&&"object"==typeof f&&r.call(f,"__await")?t.resolve(f.__await).then((function(e){n("next",e,i,s)}),(function(e){n("throw",e,i,s)})):t.resolve(f).then((function(e){l.value=e,i(l)}),(function(e){return n("throw",e,i,s)}))}s(c.arg)}(o,a,n,i)}))}return n=n?n.then(i,i):i()}}function g(e,t){var r=e.iterator[t.method];if(void 0===r){if(t.delegate=null,"throw"===t.method){if(e.iterator.return&&(t.method="return",t.arg=void 0,g(e,t),"throw"===t.method))return l;t.method="throw",t.arg=new TypeError("The iterator does not provide a 'throw' method")}return l}var n=u(r,e.iterator,t.arg);if("throw"===n.type)return t.method="throw",t.arg=n.arg,t.delegate=null,l;var o=n.arg;return o?o.done?(t[e.resultName]=o.value,t.next=e.nextLoc,"return"!==t.method&&(t.method="next",t.arg=void 0),t.delegate=null,l):o:(t.method="throw",t.arg=new TypeError("iterator result is not an object"),t.delegate=null,l)}function w(e){var t={tryLoc:e[0]};1 in e&&(t.catchLoc=e[1]),2 in e&&(t.finallyLoc=e[2],t.afterLoc=e[3]),this.tryEntries.push(t)}function k(e){var t=e.completion||{};t.type="normal",delete t.arg,e.completion=t}function E(e){this.tryEntries=[{tryLoc:"root"}],e.forEach(w,this),this.reset(!0)}function S(e){if(e){var t=e[o];if(t)return t.call(e);if("function"==typeof e.next)return e;if(!isNaN(e.length)){var n=-1,a=function t(){for(;++n<e.length;)if(r.call(e,n))return t.value=e[n],t.done=!1,t;return t.value=void 0,t.done=!0,t};return a.next=a}}return{next:T}}function T(){return{value:void 0,done:!0}}return p.prototype=d,s(y,"constructor",d),s(d,"constructor",p),p.displayName=s(d,i,"GeneratorFunction"),e.isGeneratorFunction=function(e){var t="function"==typeof e&&e.constructor;return!!t&&(t===p||"GeneratorFunction"===(t.displayName||t.name))},e.mark=function(e){return Object.setPrototypeOf?Object.setPrototypeOf(e,d):(e.__proto__=d,s(e,i,"GeneratorFunction")),e.prototype=Object.create(y),e},e.awrap=function(e){return{__await:e}},x(b.prototype),s(b.prototype,a,(function(){return this})),e.AsyncIterator=b,e.async=function(t,r,n,o,a){void 0===a&&(a=Promise);var i=new b(c(t,r,n,o),a);return e.isGeneratorFunction(r)?i:i.next().then((function(e){return e.done?e.value:i.next()}))},x(y),s(y,i,"Generator"),s(y,o,(function(){return this})),s(y,"toString",(function(){return"[object Generator]"})),e.keys=function(e){var t=[];for(var r in e)t.push(r);return t.reverse(),function r(){for(;t.length;){var n=t.pop();if(n in e)return r.value=n,r.done=!1,r}return r.done=!0,r}},e.values=S,E.prototype={constructor:E,reset:function(e){if(this.prev=0,this.next=0,this.sent=this._sent=void 0,this.done=!1,this.delegate=null,this.method="next",this.arg=void 0,this.tryEntries.forEach(k),!e)for(var t in this)"t"===t.charAt(0)&&r.call(this,t)&&!isNaN(+t.slice(1))&&(this[t]=void 0)},stop:function(){this.done=!0;var e=this.tryEntries[0].completion;if("throw"===e.type)throw e.arg;return this.rval},dispatchException:function(e){if(this.done)throw e;var t=this;function n(r,n){return i.type="throw",i.arg=e,t.next=r,n&&(t.method="next",t.arg=void 0),!!n}for(var o=this.tryEntries.length-1;o>=0;--o){var a=this.tryEntries[o],i=a.completion;if("root"===a.tryLoc)return n("end");if(a.tryLoc<=this.prev){var s=r.call(a,"catchLoc"),c=r.call(a,"finallyLoc");if(s&&c){if(this.prev<a.catchLoc)return n(a.catchLoc,!0);if(this.prev<a.finallyLoc)return n(a.finallyLoc)}else if(s){if(this.prev<a.catchLoc)return n(a.catchLoc,!0)}else{if(!c)throw new Error("try statement without catch or finally");if(this.prev<a.finallyLoc)return n(a.finallyLoc)}}}},abrupt:function(e,t){for(var n=this.tryEntries.length-1;n>=0;--n){var o=this.tryEntries[n];if(o.tryLoc<=this.prev&&r.call(o,"finallyLoc")&&this.prev<o.finallyLoc){var a=o;break}}a&&("break"===e||"continue"===e)&&a.tryLoc<=t&&t<=a.finallyLoc&&(a=null);var i=a?a.completion:{};return i.type=e,i.arg=t,a?(this.method="next",this.next=a.finallyLoc,l):this.complete(i)},complete:function(e,t){if("throw"===e.type)throw e.arg;return"break"===e.type||"continue"===e.type?this.next=e.arg:"return"===e.type?(this.rval=this.arg=e.arg,this.method="return",this.next="end"):"normal"===e.type&&t&&(this.next=t),l},finish:function(e){for(var t=this.tryEntries.length-1;t>=0;--t){var r=this.tryEntries[t];if(r.finallyLoc===e)return this.complete(r.completion,r.afterLoc),k(r),l}},catch:function(e){for(var t=this.tryEntries.length-1;t>=0;--t){var r=this.tryEntries[t];if(r.tryLoc===e){var n=r.completion;if("throw"===n.type){var o=n.arg;k(r)}return o}}throw new Error("illegal catch attempt")},delegateYield:function(e,t,r){return this.delegate={iterator:S(e),resultName:t,nextLoc:r},"next"===this.method&&(this.arg=void 0),l}},e}(e.exports);try{regeneratorRuntime=t}catch(e){"object"==typeof globalThis?globalThis.regeneratorRuntime=t:Function("r","regeneratorRuntime = r")(t)}})),f=function(e){var o=e.pollingFrequency,a=void 0===o?1e3:o,i=n.memory(),s=t.useState(!1),c=s[0],u=s[1];return t.useEffect((function(){var e=setInterval((function(){return u(!c)}),a);return function(){return clearInterval(e)}}),[a]),r.createElement("div",null,Object.entries(i).map((function(e){var t=e[0];return r.createElement("p",{key:t},t+": "+e[1])})))},p=function(e){return Math.round(e/1024).toString().replace(/\B(?=(\d{3})+(?!\d))/g,",")},d=function(){var e=a(l.mark((function e(t){var r;return l.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return r={kernelMs:0,wallMs:0},e.next=3,n.profile(a(l.mark((function e(){return l.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,n.time(t);case 2:r=e.sent;case 3:case"end":return e.stop()}}),e)}))));case 3:return e.abrupt("return",i({},e.sent,r));case 5:case"end":return e.stop()}}),e)})));return function(t){return e.apply(this,arguments)}}(),h=function(e){var t=e.peakBytes,n=e.newTensors,o=e.kernelMs,a=e.drawingTime,i=e.fps;return r.createElement("div",null,r.createElement("div",{style:v.container},r.createElement("p",null,"New Bytes: ",p(e.newBytes)," KB "),r.createElement("p",null,"New Tensors: ",n),r.createElement("p",null,"Peak Bytes: ",p(t<0?0:t)," KB"),r.createElement("p",null,"Execution: ",o," ms"),!!a&&r.createElement("p",null,"Drawing Time: ",a.toFixed(2)," ms"),!!i&&r.createElement("p",null,"FPS: ",i)),r.createElement("div",{style:v.container},r.createElement(f,{pollingFrequency:1e3})))};h.perfInfo=d;var v={container:{backgroundColor:"#3f4255",borderColor:"#44475c",borderWidth:1,color:"#fff",fontSize:16,margin:20,opacity:"0.8",padding:10,width:"20%",fontFamily:"sans-serif"}},m=function(e){var o=e.detectionResults,i=e.height,s=e.modelConfig,u=e.onDrawComplete,f=e.width,p=t.useRef(null);function d(){return(d=a(l.mark((function e(){var t,r,n,a,d,h,v,m,y,x,b,g,w,k,E,S,T,L,I;return l.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:for(t=o.detections,r=o.maxIndices,n=o.scores,a=o.boxes,h=null==(d=p.current)?void 0:d.getContext("2d"),d.width=f,d.height=i,h.font="16px sans-serif",h.textBaseline="top",v=performance.now(),m=c(t);!(y=m()).done;)b=y.value,h.strokeStyle="#0F0",h.lineWidth=4,h.globalCompositeOperation="destination-over",g=r[b],w=null==(x=s.labels)?void 0:x[g],k=n[b],h.strokeRect(T=(E=a[b])[1]>0?E[1]*f:0,S=E[0]>0?E[0]*i:0,(E[3]-E[1])*f,(E[2]-E[0])*i),w&&(h.globalCompositeOperation="source-over",h.fillStyle="#0B0",L=w+" "+Math.round(100*k)+"%",I=h.measureText(L).width,h.fillRect(T,S,I+4,20),h.fillStyle="#000000",h.fillText(L,T,S)),null==u||u(performance.now()-v);case 9:case"end":return e.stop()}}),e)})))).apply(this,arguments)}return t.useEffect((function(){n.ready().then((function(){!function(){d.apply(this,arguments)}()}))}),[o,i,s,f]),r.createElement("div",{style:{left:0,position:"absolute",width:f,height:i,top:0}},r.createElement("canvas",{ref:p}))},y={modelType:"ssd",threshold:.4,maxResults:20,iouThreshold:.5,nmsActive:!0,topK:5};function x(e,t){return b.apply(this,arguments)}function b(){return(b=a(l.mark((function e(t,r){var o,a,i,s,c,u,f,p,d,h,v,m,y,x;return l.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return o=n.topk(t[0]),a=t[1].squeeze(),i=o.values.squeeze(),s=r.threshold,u=void 0===(c=r.maxResults)?20:c,f=r.iouThreshold,p=r.nmsActive,e.next=6,Promise.all([o.indices.data(),i.array(),a.array()]);case 6:return h=(d=e.sent)[0],v=d[1],m=d[2],e.next=12,n.image.nonMaxSuppressionWithScoreAsync(a,i,u,f,s,p?1:0);case 12:return y=e.sent,e.next=15,y.selectedIndices.data();case 15:return x=e.sent,n.dispose([y.selectedIndices,y.selectedScores]),e.abrupt("return",{detections:x,maxIndices:h,scores:v,boxes:m});case 18:case"end":return e.stop()}}),e)})))).apply(this,arguments)}function g(e,t){return w.apply(this,arguments)}function w(){return(w=a(l.mark((function e(t,r){var n,o,a,i,s,c,u,f,p,d,h,v;return l.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,t.data();case 2:for(n=e.sent,o=[],a=0;a<n.length;a++)o.push({value:n[a],index:a});for(o.sort((function(e,t){return t.value-e.value})),i=new Float32Array(r.topK),s=new Int32Array(r.topK),c=0;c<r.topK;c++)i[c]=o[c].value,s[c]=o[c].index;for(u=r.threshold,p=void 0===(f=r.maxResults)?r.topK:f,d=[],h=0;h<p;h++)d.push(i[h]);return v=d.filter((function(e){return e>u})),e.abrupt("return",v);case 14:case"end":return e.stop()}}),e)})))).apply(this,arguments)}function k(e,t){return E.apply(this,arguments)}function E(){return(E=a(l.mark((function e(t,r){var o;return l.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return o=n.expandDims(t,0),e.next=3,r.executeAsync(o);case 3:return e.abrupt("return",e.sent);case 5:case"end":return e.stop()}}),e)})))).apply(this,arguments)}function S(e,t,r){return T.apply(this,arguments)}function T(){return(T=a(l.mark((function e(t,r,o){var a,i,s,c;return l.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return a=t.toFloat().div(255),i=a,t.shape[0]===o&&t.shape[1]===o||(i=n.image.resizeBilinear(a,[o,o],!0)),s=i.reshape([1,o,o,3]),c=r.predict(s),e.abrupt("return",c);case 6:case"end":return e.stop()}}),e)})))).apply(this,arguments)}function L(e,t){return I.apply(this,arguments)}function I(){return(I=a(l.mark((function e(t,r){var n,o;return l.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(void 0===r&&(r=y),"ssd"!==(null==(n=r)?void 0:n.modelType)){e.next=7;break}return e.next=4,x(t,i({},y,r));case 4:return e.abrupt("return",e.sent);case 7:if("pose"!==(null==(o=r)?void 0:o.modelType)){e.next=11;break}return e.abrupt("return",t[0]);case 11:return e.next=13,g(t,i({},y,r));case 13:return e.abrupt("return",e.sent);case 14:case"end":return e.stop()}}),e)})))).apply(this,arguments)}function O(e,t){return C.apply(this,arguments)}function C(){return(C=a(l.mark((function e(t,r){var n,o,a,i,s,c,u;return l.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(void 0===r&&(r=y),a=r.labels,"ssd"!==(null==(n=r)?void 0:n.modelType)){e.next=8;break}return i=t.maxIndices,s=t.scores,c=Array.from(t.detections).map((function(e,t){return{class:t,classLabel:a?a[i[e]]:"class "+t,score:s[e]}})),e.abrupt("return",c);case 8:if("pose"!==(null==(o=r)?void 0:o.modelType)){e.next=12;break}return e.abrupt("return",t);case 12:return u=t.map((function(e,t){return{class:t,classLabel:a?a[t]:"class "+t,score:e}})),e.abrupt("return",u);case 14:case"end":return e.stop()}}),e)})))).apply(this,arguments)}var j={modelType:"ssd",threshold:.4,maxResults:20,iouThreshold:.5,nmsActive:!0,topK:5},R=function(e){var t=e.devices,n=t&&t.map((function(e){return r.createElement("option",{key:e.deviceId,value:e.deviceId},e.label)}));return r.createElement("div",null,r.createElement("select",{onChange:function(t){return e.onChange(t.target.value)},value:e.select},r.createElement("option",{disabled:!!e.select,value:"None"},"Choose a Camera"),n))};function A(e){return e?{width:e.offsetWidth,height:e.offsetHeight}:{}}var P={modelType:"ssd",threshold:.4,maxResults:20,iouThreshold:.5,nmsActive:!0,topK:5},D=function(){var e=a(l.mark((function e(t){return l.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",new Promise((function(e){return setTimeout(e,t)})));case 1:case"end":return e.stop()}}),e)})));return function(t){return e.apply(this,arguments)}}(),F={modelType:"ssd",threshold:.4,maxResults:20,iouThreshold:.5,nmsActive:!0,topK:5},z=!1;exports.AILabImage=function(e){var o,s,c,u,f=e.model,p=e.modelConfig,v=e.ObjectDetectionUI,y=void 0===v?m:v,x=e.onInference,b=e.perf,g=e.perfCallback,w=e.src,E=e.size,T=void 0===E?224:E,I=e.visual,C=e.displaySize,R=e.style,A=t.useState(!1),P=A[0],D=A[1],F=t.useRef(null),z=t.useState(0),_=z[0],M=z[1],B=t.useState(),N=B[0],K=B[1],W=t.useState({}),q=W[0],U=W[1],G=t.useState(),H=G[0],Y=G[1],V=function(){var e=a(l.mark((function e(t){var r,o,a;return l.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(o=n.browser.fromPixels(r=F.current),"ssd"!==(null==p?void 0:p.modelType)){e.next=9;break}return H&&n.dispose([H[0],H[1]]),e.next=6,k(o,t);case 6:a=e.sent,e.next=19;break;case 9:if("pose"!==(null==p?void 0:p.modelType)){e.next=15;break}return e.next=12,t.estimatePoses(r,{maxPoses:1,flipHorizontal:!1});case 12:a=e.sent,e.next=19;break;case 15:return H&&n.dispose(H),e.next=18,S(o,t,T);case 18:a=e.sent;case 19:Y(a);case 20:case"end":return e.stop()}}),e)})));return function(t){return e.apply(this,arguments)}}();return t.useEffect((function(){n.ready().then((function(){D(!0)}))}),[]),t.useEffect((function(){var e=function(){var e=a(l.mark((function e(){var t;return l.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(!b&&!g){e.next=8;break}return e.next=3,d(a(l.mark((function e(){return l.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,V(f);case 2:case"end":return e.stop()}}),e)}))));case 3:t=e.sent,b&&K(t),g&&g(t),e.next=10;break;case 8:return e.next=10,V(f);case 10:case"end":return e.stop()}}),e)})));return function(){return e.apply(this,arguments)}}();if(P){var t=F.current;null!=t&&t.complete?e():t.onload=e}}),[w,P]),t.useEffect((function(){a(l.mark((function e(){var t,r;return l.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(!H){e.next=9;break}return e.next=3,L(H,p);case 3:return t=e.sent,e.next=6,O(t,p);case 6:r=e.sent,U(t),null==x||x(r);case 9:case"end":return e.stop()}}),e)})))()}),[p,H]),r.createElement("div",{style:R},r.createElement("div",{style:{position:"relative"}},b&&N&&r.createElement("div",{style:{position:"absolute",left:0,right:0,bottom:0}},r.createElement(h,Object.assign({},N,{drawingTime:_}))),r.createElement("img",{ref:F,src:w,height:"max"===C?"100%":void 0,width:"max"===C?"100%":void 0}),I&&r.createElement(y,{detectionResults:q,height:null!=(o=null==(s=F.current)?void 0:s.offsetHeight)?o:0,modelConfig:i({},j,p),onDrawComplete:function(e){_||M(e)},width:null!=(c=null==(u=F.current)?void 0:u.offsetWidth)?c:0})))},exports.AILabLocalVideo=function(e){var o,s,c,u,f=e.model,p=e.modelConfig,v=e.ObjectDetectionUI,y=void 0===v?m:v,x=e.onInference,b=e.perf,g=e.perfCallback,w=e.size,E=void 0===w?224:w,T=e.src,I=e.visual,C=e.displaySize,j=e.style,R=t.useState(!1),A=R[0],P=R[1],D=t.useState(),_=D[0],M=D[1],B=t.useState(0),N=B[0],K=B[1],W=t.useRef(null),q=t.useState({}),U=q[0],G=q[1],H=t.useState(),Y=H[0],V=H[1],$=t.useRef({lastTensor:-1,fps:0,calculateFps:function(){return Math.round(100*$.current.fps)/100}});function J(e){return Q.apply(this,arguments)}function Q(){return(Q=a(l.mark((function e(t){var r;return l.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(!(!W.current||z||W.current.readyState<2)){e.next=3;break}return requestAnimationFrame((function(){return J(t)})),e.abrupt("return");case 3:if(z=!0,r=n.browser.fromPixels(W.current),"ssd"!==(null==p?void 0:p.modelType)){e.next=13;break}return Y&&n.dispose([Y[0],Y[1]]),e.next=9,k(r,t);case 9:V(e.sent),e.next=18;break;case 13:return Y&&n.dispose(Y),e.next=16,S(r,t,E);case 16:V(e.sent);case 18:z=!1;case 19:case"end":return e.stop()}}),e)})))).apply(this,arguments)}function X(){if(-1!==$.current.lastTensor){var e=performance.now()-$.current.lastTensor;$.current.fps=1e3/e}$.current.lastTensor=performance.now()}function Z(){return ee.apply(this,arguments)}function ee(){return(ee=a(l.mark((function e(){var t;return l.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(!z){e.next=2;break}return e.abrupt("return");case 2:if(console.log("calling runInference"),!b&&!g){e.next=12;break}return X(),e.next=7,d(a(l.mark((function e(){return l.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,J(f);case 2:case"end":return e.stop()}}),e)}))));case 7:t=e.sent,b&&M(t),g&&g(t),e.next=14;break;case 12:return e.next=14,J(f);case 14:!1===W.current.paused&&requestAnimationFrame(Z);case 15:case"end":return e.stop()}}),e)})))).apply(this,arguments)}return t.useEffect((function(){n.ready().then((function(){P(!0)}))}),[]),t.useEffect((function(){a(l.mark((function e(){var t,r;return l.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(!Y){e.next=9;break}return e.next=3,L(Y,p);case 3:return t=e.sent,e.next=6,O(t,p);case 6:r=e.sent,G(t),null==x||x(r);case 9:case"end":return e.stop()}}),e)})))()}),[p,Y]),r.createElement("div",{style:j},r.createElement("div",{style:{position:"relative"}},b&&_&&!!N&&r.createElement("div",{style:{position:"absolute",left:0,right:0,bottom:0}},r.createElement(h,Object.assign({},_,{drawingTime:N,fps:$.current.calculateFps()}))),I&&r.createElement(y,{detectionResults:U,height:null!=(o=null==(s=W.current)?void 0:s.offsetHeight)?o:0,modelConfig:i({},F,p),onDrawComplete:function(e){N||K(e)},width:null!=(c=null==(u=W.current)?void 0:u.offsetWidth)?c:0}),r.createElement("video",{crossOrigin:"anonymous",id:"video",src:T,ref:W,width:"max"===C?"100%":void 0,height:"max"===C?"100%":void 0,controls:!0,onEnded:function(){W.current&&(W.current.pause(),M(void 0))},onPause:function(){$.current.lastTensor=-1},onPlay:function(){A&&Z()},muted:!0})))},exports.AILabObjectDetectionUI=m,exports.AILabWebCam=function(e){var o,s,c,u,f=e.model,p=e.modelConfig,v=e.ObjectDetectionUI,y=void 0===v?m:v,x=e.onInference,b=e.perf,g=e.perfCallback,w=e.size,E=void 0===w?224:w,T=e.visual,I=e.displaySize,C=e.style,j=t.useRef(null),F=t.useRef(null),z=t.useRef(null),_=t.useState(!1),M=_[0],B=_[1],N=t.useState(null),K=N[0],W=N[1],q=t.useState(localStorage.getItem("currentDevice")||""),U=q[0],G=q[1],H=t.useState(),Y=H[0],V=H[1],$=t.useState(0),J=$[0],Q=$[1],X=t.useState({}),Z=X[0],ee=X[1],te=t.useState(),re=te[0],ne=te[1];function oe(e,t){return ae.apply(this,arguments)}function ae(){return(ae=a(l.mark((function e(t,r){var o;return l.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if("ssd"!==(null==p?void 0:p.modelType)){e.next=7;break}return re&&n.dispose([re[0],re[1]]),e.next=4,k(t,r);case 4:o=e.sent,e.next=17;break;case 7:if("pose"!==(null==p?void 0:p.modelType)){e.next=13;break}return e.next=10,r.estimatePoses(j.current,{maxPoses:1,flipHorizontal:!1});case 10:o=e.sent,e.next=17;break;case 13:return re&&n.dispose(re),e.next=16,S(t,r,E);case 16:o=e.sent;case 17:ne(o);case 18:case"end":return e.stop()}}),e)})))).apply(this,arguments)}function ie(e){return se.apply(this,arguments)}function se(){return(se=a(l.mark((function e(t){var r,n;return l.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(!F.current){e.next=2;break}return e.abrupt("return");case 2:return e.next=4,ue();case 4:return r={deviceId:t?{exact:t}:void 0,width:{ideal:me,max:me},height:{ideal:he,max:he},facingMode:"user"},e.prev=6,e.next=9,navigator.mediaDevices.getUserMedia({audio:!1,video:r});case 9:F.current=n=e.sent,"srcObject"in j.current?j.current.srcObject=n:j.current.src=window.URL.createObjectURL(n),e.next=19;break;case 14:e.prev=14,e.t0=e.catch(6),localStorage.clear(),alert("Something went wrong for this device! Please change browsers, try again, or contribute to the site's open source!"),console.log(e.t0);case 19:case"end":return e.stop()}}),e,null,[[6,14]])})))).apply(this,arguments)}function ce(){var e,t;null==(e=F.current)||e.getTracks().forEach((function(e){e.stop()})),j.current&&(j.current.srcObject=null),F.current=null,null==(t=z.current)||t.stop()}function ue(){return le.apply(this,arguments)}function le(){return(le=a(l.mark((function e(){var t;return l.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,navigator.mediaDevices.enumerateDevices();case 2:t=e.sent.filter((function(e){return"videoinput"===e.kind})),W(t);case 5:case"end":return e.stop()}}),e)})))).apply(this,arguments)}function fe(){return(fe=a(l.mark((function e(t){return l.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:G(t),localStorage.setItem("currentDevice",t),ce(),ie(t);case 4:case"end":return e.stop()}}),e)})))).apply(this,arguments)}t.useEffect((function(){n.ready().then((function(){return B(!0)}))}),[]),t.useEffect((function(){var e=!0;return M&&(function(){var t=a(l.mark((function t(){var r,o,i;return l.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return o=function(){return(o=a(l.mark((function e(){return l.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(z.current){e.next=2;break}return e.abrupt("return");case 2:return e.next=4,z.current.capture();case 4:oe(e.sent,f);case 6:case"end":return e.stop()}}),e)})))).apply(this,arguments)},r=function(){return o.apply(this,arguments)},console.log("quick delay"),t.next=5,n.data.webcam(j.current);case 5:if(z.current=t.sent,!b&&!g){t.next=20;break}case 7:if(!F.current){t.next=18;break}if(!e){t.next=16;break}return t.next=11,d(r);case 11:return i=t.sent,b&&V(i),g&&g(i),t.next=16,D(1e3);case 16:t.next=7;break;case 18:t.next=27;break;case 20:if(!F.current){t.next=27;break}return t.next=23,r();case 23:return t.next=25,D(1e3);case 25:t.next=20;break;case 27:case"end":return t.stop()}}),t)})));return function(){return t.apply(this,arguments)}}()(),ie(U)),function(){ce(),e=!1}}),[M]),t.useEffect((function(){a(l.mark((function e(){var t,r;return l.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(!re){e.next=9;break}return e.next=3,L(re,p);case 3:return t=e.sent,e.next=6,O(t,p);case 6:r=e.sent,ee(t),null==x||x(r);case 9:case"end":return e.stop()}}),e)})))()}),[p,re]);var pe=function(e){var r=t.useState(A(e.current)),n=r[0],o=r[1];function a(){e&&e.current&&o(A(e.current))}return t.useLayoutEffect((function(){return a(),window.addEventListener("resize",a),function(){window.removeEventListener("resize",a)}}),[]),n}(j),de=pe.height,he=void 0===de?0:de,ve=pe.width,me=void 0===ve?0:ve;return r.createElement("div",{style:C},r.createElement("div",{style:{position:"relative"}},b&&Y&&!!J&&r.createElement("div",{style:{position:"absolute",left:0,right:0,bottom:0}},r.createElement(h,Object.assign({},Y,{drawingTime:J}))),r.createElement("video",{ref:j,autoPlay:!0,height:"max"===I?"100%":void 0,width:"max"===I?"100%":void 0}),T&&r.createElement(y,{detectionResults:Z,height:null!=(o=null==(s=j.current)?void 0:s.offsetHeight)?o:0,modelConfig:i({},P,p),onDrawComplete:function(e){J||Q(e)},width:null!=(c=null==(u=j.current)?void 0:u.offsetWidth)?c:0})),r.createElement("div",null,r.createElement(R,{select:U,devices:K,onChange:function(e){return fe.apply(this,arguments)}}),r.createElement("button",{onClick:ce},"Stop WebCam")))},exports.CLASSES=["person","bicycle","car","motorcycle","airplane","bus","train","truck","boat","traffic light","fire hydrant","unused","stop sign","parking meter","bench","bird","cat","dog","horse","sheep","cow","elephant","bear","zebra","giraffe","unused","backpack","umbrella","unused","unused","handbag","tie","suitcase","frisbee","skis","snowboard","sports ball","kite","baseball bat","baseball glove","skateboard","surfboard","tennis racket","bottle","unused","wine glass","cup","fork","knife","spoon","bowl","banana","apple","sandwich","orange","broccoli","carrot","hot dog","pizza","donut","cake","chair","couch","potted plant","bed","unused","dining table","unused","unused","toilet","unused","tv","laptop","mouse","remote","keyboard","cell phone","microwave","oven","toaster","sink","refrigerator","unused","book","clock","vase","scissors","teddy bear","hair drier","toothbrush"],exports.SimpleObjectDetectionUI=function(e){var o=e.detectionResults,i=e.height,s=e.modelConfig,u=e.onDrawComplete,f=e.width,p=t.useRef(null);function d(){return h.apply(this,arguments)}function h(){return(h=a(l.mark((function e(){var t,r,n,a,s,d,h,v,m;return l.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:for(t=o.detections,r=o.boxes,a=null==(n=p.current)?void 0:n.getContext("2d"),n.width=f,n.height=i,a.font="16px sans-serif",a.textBaseline="top",s=performance.now(),d=c(t);!(h=d()).done;)v=h.value,a.strokeStyle="#F00",a.lineWidth=4,a.globalCompositeOperation="destination-over",a.strokeRect((m=r[v])[1]>0?m[1]*f:0,m[0]>0?m[0]*i:0,(m[3]-m[1])*f,(m[2]-m[0])*i),null==u||u(performance.now()-s);case 9:case"end":return e.stop()}}),e)})))).apply(this,arguments)}return t.useEffect((function(){n.ready().then(d)}),[o,i,s,f]),r.createElement("canvas",{ref:p,style:{position:"absolute",left:0,top:0,height:i,width:f}})},exports.classificationModelDetection=g,exports.getInferenceData=O,exports.getModelDetections=L,exports.predictClassification=S,exports.predictSSD=k,exports.ssdModelDetection=x;
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e,t=require("react"),r=(e=t)&&"object"==typeof e&&"default"in e?e.default:e,n=require("@tensorflow/tfjs");function o(e,t,r,n,o,a,i){try{var s=e[a](i),c=s.value}catch(e){return void r(e)}s.done?t(c):Promise.resolve(c).then(n,o)}function a(e){return function(){var t=this,r=arguments;return new Promise((function(n,a){var i=e.apply(t,r);function s(e){o(i,n,a,s,c,"next",e)}function c(e){o(i,n,a,s,c,"throw",e)}s(void 0)}))}}function i(){return(i=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var r=arguments[t];for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&(e[n]=r[n])}return e}).apply(this,arguments)}function s(e,t){(null==t||t>e.length)&&(t=e.length);for(var r=0,n=new Array(t);r<t;r++)n[r]=e[r];return n}function c(e,t){var r="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(r)return(r=r.call(e)).next.bind(r);if(Array.isArray(e)||(r=function(e,t){if(e){if("string"==typeof e)return s(e,void 0);var r=Object.prototype.toString.call(e).slice(8,-1);return"Object"===r&&e.constructor&&(r=e.constructor.name),"Map"===r||"Set"===r?Array.from(e):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?s(e,void 0):void 0}}(e))||t&&e&&"number"==typeof e.length){r&&(e=r);var n=0;return function(){return n>=e.length?{done:!0}:{done:!1,value:e[n++]}}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}function u(e,t){return e(t={exports:{}},t.exports),t.exports}var l=u((function(e){var t=function(e){var t=Object.prototype,r=t.hasOwnProperty,n="function"==typeof Symbol?Symbol:{},o=n.iterator||"@@iterator",a=n.asyncIterator||"@@asyncIterator",i=n.toStringTag||"@@toStringTag";function s(e,t,r){return Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}),e[t]}try{s({},"")}catch(e){s=function(e,t,r){return e[t]=r}}function c(e,t,r,n){var o=Object.create((t&&t.prototype instanceof f?t:f).prototype),a=new E(n||[]);return o._invoke=function(e,t,r){var n="suspendedStart";return function(o,a){if("executing"===n)throw new Error("Generator is already running");if("completed"===n){if("throw"===o)throw a;return{value:void 0,done:!0}}for(r.method=o,r.arg=a;;){var i=r.delegate;if(i){var s=g(i,r);if(s){if(s===l)continue;return s}}if("next"===r.method)r.sent=r._sent=r.arg;else if("throw"===r.method){if("suspendedStart"===n)throw n="completed",r.arg;r.dispatchException(r.arg)}else"return"===r.method&&r.abrupt("return",r.arg);n="executing";var c=u(e,t,r);if("normal"===c.type){if(n=r.done?"completed":"suspendedYield",c.arg===l)continue;return{value:c.arg,done:r.done}}"throw"===c.type&&(n="completed",r.method="throw",r.arg=c.arg)}}}(e,r,a),o}function u(e,t,r){try{return{type:"normal",arg:e.call(t,r)}}catch(e){return{type:"throw",arg:e}}}e.wrap=c;var l={};function f(){}function p(){}function d(){}var h={};s(h,o,(function(){return this}));var v=Object.getPrototypeOf,m=v&&v(v(S([])));m&&m!==t&&r.call(m,o)&&(h=m);var y=d.prototype=f.prototype=Object.create(h);function x(e){["next","throw","return"].forEach((function(t){s(e,t,(function(e){return this._invoke(t,e)}))}))}function b(e,t){var n;this._invoke=function(o,a){function i(){return new t((function(n,i){!function n(o,a,i,s){var c=u(e[o],e,a);if("throw"!==c.type){var l=c.arg,f=l.value;return f&&"object"==typeof f&&r.call(f,"__await")?t.resolve(f.__await).then((function(e){n("next",e,i,s)}),(function(e){n("throw",e,i,s)})):t.resolve(f).then((function(e){l.value=e,i(l)}),(function(e){return n("throw",e,i,s)}))}s(c.arg)}(o,a,n,i)}))}return n=n?n.then(i,i):i()}}function g(e,t){var r=e.iterator[t.method];if(void 0===r){if(t.delegate=null,"throw"===t.method){if(e.iterator.return&&(t.method="return",t.arg=void 0,g(e,t),"throw"===t.method))return l;t.method="throw",t.arg=new TypeError("The iterator does not provide a 'throw' method")}return l}var n=u(r,e.iterator,t.arg);if("throw"===n.type)return t.method="throw",t.arg=n.arg,t.delegate=null,l;var o=n.arg;return o?o.done?(t[e.resultName]=o.value,t.next=e.nextLoc,"return"!==t.method&&(t.method="next",t.arg=void 0),t.delegate=null,l):o:(t.method="throw",t.arg=new TypeError("iterator result is not an object"),t.delegate=null,l)}function w(e){var t={tryLoc:e[0]};1 in e&&(t.catchLoc=e[1]),2 in e&&(t.finallyLoc=e[2],t.afterLoc=e[3]),this.tryEntries.push(t)}function k(e){var t=e.completion||{};t.type="normal",delete t.arg,e.completion=t}function E(e){this.tryEntries=[{tryLoc:"root"}],e.forEach(w,this),this.reset(!0)}function S(e){if(e){var t=e[o];if(t)return t.call(e);if("function"==typeof e.next)return e;if(!isNaN(e.length)){var n=-1,a=function t(){for(;++n<e.length;)if(r.call(e,n))return t.value=e[n],t.done=!1,t;return t.value=void 0,t.done=!0,t};return a.next=a}}return{next:L}}function L(){return{value:void 0,done:!0}}return p.prototype=d,s(y,"constructor",d),s(d,"constructor",p),p.displayName=s(d,i,"GeneratorFunction"),e.isGeneratorFunction=function(e){var t="function"==typeof e&&e.constructor;return!!t&&(t===p||"GeneratorFunction"===(t.displayName||t.name))},e.mark=function(e){return Object.setPrototypeOf?Object.setPrototypeOf(e,d):(e.__proto__=d,s(e,i,"GeneratorFunction")),e.prototype=Object.create(y),e},e.awrap=function(e){return{__await:e}},x(b.prototype),s(b.prototype,a,(function(){return this})),e.AsyncIterator=b,e.async=function(t,r,n,o,a){void 0===a&&(a=Promise);var i=new b(c(t,r,n,o),a);return e.isGeneratorFunction(r)?i:i.next().then((function(e){return e.done?e.value:i.next()}))},x(y),s(y,i,"Generator"),s(y,o,(function(){return this})),s(y,"toString",(function(){return"[object Generator]"})),e.keys=function(e){var t=[];for(var r in e)t.push(r);return t.reverse(),function r(){for(;t.length;){var n=t.pop();if(n in e)return r.value=n,r.done=!1,r}return r.done=!0,r}},e.values=S,E.prototype={constructor:E,reset:function(e){if(this.prev=0,this.next=0,this.sent=this._sent=void 0,this.done=!1,this.delegate=null,this.method="next",this.arg=void 0,this.tryEntries.forEach(k),!e)for(var t in this)"t"===t.charAt(0)&&r.call(this,t)&&!isNaN(+t.slice(1))&&(this[t]=void 0)},stop:function(){this.done=!0;var e=this.tryEntries[0].completion;if("throw"===e.type)throw e.arg;return this.rval},dispatchException:function(e){if(this.done)throw e;var t=this;function n(r,n){return i.type="throw",i.arg=e,t.next=r,n&&(t.method="next",t.arg=void 0),!!n}for(var o=this.tryEntries.length-1;o>=0;--o){var a=this.tryEntries[o],i=a.completion;if("root"===a.tryLoc)return n("end");if(a.tryLoc<=this.prev){var s=r.call(a,"catchLoc"),c=r.call(a,"finallyLoc");if(s&&c){if(this.prev<a.catchLoc)return n(a.catchLoc,!0);if(this.prev<a.finallyLoc)return n(a.finallyLoc)}else if(s){if(this.prev<a.catchLoc)return n(a.catchLoc,!0)}else{if(!c)throw new Error("try statement without catch or finally");if(this.prev<a.finallyLoc)return n(a.finallyLoc)}}}},abrupt:function(e,t){for(var n=this.tryEntries.length-1;n>=0;--n){var o=this.tryEntries[n];if(o.tryLoc<=this.prev&&r.call(o,"finallyLoc")&&this.prev<o.finallyLoc){var a=o;break}}a&&("break"===e||"continue"===e)&&a.tryLoc<=t&&t<=a.finallyLoc&&(a=null);var i=a?a.completion:{};return i.type=e,i.arg=t,a?(this.method="next",this.next=a.finallyLoc,l):this.complete(i)},complete:function(e,t){if("throw"===e.type)throw e.arg;return"break"===e.type||"continue"===e.type?this.next=e.arg:"return"===e.type?(this.rval=this.arg=e.arg,this.method="return",this.next="end"):"normal"===e.type&&t&&(this.next=t),l},finish:function(e){for(var t=this.tryEntries.length-1;t>=0;--t){var r=this.tryEntries[t];if(r.finallyLoc===e)return this.complete(r.completion,r.afterLoc),k(r),l}},catch:function(e){for(var t=this.tryEntries.length-1;t>=0;--t){var r=this.tryEntries[t];if(r.tryLoc===e){var n=r.completion;if("throw"===n.type){var o=n.arg;k(r)}return o}}throw new Error("illegal catch attempt")},delegateYield:function(e,t,r){return this.delegate={iterator:S(e),resultName:t,nextLoc:r},"next"===this.method&&(this.arg=void 0),l}},e}(e.exports);try{regeneratorRuntime=t}catch(e){"object"==typeof globalThis?globalThis.regeneratorRuntime=t:Function("r","regeneratorRuntime = r")(t)}})),f=function(e){var o=e.pollingFrequency,a=void 0===o?1e3:o,i=n.memory(),s=t.useState(!1),c=s[0],u=s[1];return t.useEffect((function(){var e=setInterval((function(){return u(!c)}),a);return function(){return clearInterval(e)}}),[a]),r.createElement("div",null,Object.entries(i).map((function(e){var t=e[0];return r.createElement("p",{key:t},t+": "+e[1])})))},p=function(e){return Math.round(e/1024).toString().replace(/\B(?=(\d{3})+(?!\d))/g,",")},d=function(){var e=a(l.mark((function e(t){var r;return l.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return r={kernelMs:0,wallMs:0},e.next=3,n.profile(a(l.mark((function e(){return l.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,n.time(t);case 2:r=e.sent;case 3:case"end":return e.stop()}}),e)}))));case 3:return e.abrupt("return",i({},e.sent,r));case 5:case"end":return e.stop()}}),e)})));return function(t){return e.apply(this,arguments)}}(),h=function(e){var t=e.peakBytes,n=e.newTensors,o=e.kernelMs,a=e.drawingTime,i=e.fps;return r.createElement("div",null,r.createElement("div",{style:v.container},r.createElement("p",null,"New Bytes: ",p(e.newBytes)," KB "),r.createElement("p",null,"New Tensors: ",n),r.createElement("p",null,"Peak Bytes: ",p(t<0?0:t)," KB"),r.createElement("p",null,"Execution: ",o," ms"),!!a&&r.createElement("p",null,"Drawing Time: ",a.toFixed(2)," ms"),!!i&&r.createElement("p",null,"FPS: ",i)),r.createElement("div",{style:v.container},r.createElement(f,{pollingFrequency:1e3})))};h.perfInfo=d;var v={container:{backgroundColor:"#3f4255",borderColor:"#44475c",borderWidth:1,color:"#fff",fontSize:16,margin:20,opacity:"0.8",padding:10,width:"20%",fontFamily:"sans-serif"}},m=function(e){var o=e.detectionResults,i=e.height,s=e.modelConfig,u=e.onDrawComplete,f=e.width,p=t.useRef(null);function d(){return(d=a(l.mark((function e(){var t,r,n,a,d,h,v,m,y,x,b,g,w,k,E,S,L,T,I;return l.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:for(t=o.detections,r=o.maxIndices,n=o.scores,a=o.boxes,h=null==(d=p.current)?void 0:d.getContext("2d"),d.width=f,d.height=i,h.font="16px sans-serif",h.textBaseline="top",v=performance.now(),m=c(t);!(y=m()).done;)b=y.value,h.strokeStyle="#0F0",h.lineWidth=4,h.globalCompositeOperation="destination-over",g=r[b],w=null==(x=s.labels)?void 0:x[g],k=n[b],h.strokeRect(L=(E=a[b])[1]>0?E[1]*f:0,S=E[0]>0?E[0]*i:0,(E[3]-E[1])*f,(E[2]-E[0])*i),w&&(h.globalCompositeOperation="source-over",h.fillStyle="#0B0",T=w+" "+Math.round(100*k)+"%",I=h.measureText(T).width,h.fillRect(L,S,I+4,20),h.fillStyle="#000000",h.fillText(T,L,S)),null==u||u(performance.now()-v);case 9:case"end":return e.stop()}}),e)})))).apply(this,arguments)}return t.useEffect((function(){n.ready().then((function(){!function(){d.apply(this,arguments)}()}))}),[o,i,s,f]),r.createElement("div",{style:{left:0,position:"absolute",width:f,height:i,top:0}},r.createElement("canvas",{ref:p}))},y={modelType:"ssd",threshold:.4,maxResults:20,iouThreshold:.5,nmsActive:!0,topK:5};function x(e,t){return b.apply(this,arguments)}function b(){return(b=a(l.mark((function e(t,r){var o,a,i,s,c,u,f,p,d,h,v,m,y,x;return l.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return o=n.topk(t[0]),a=t[1].squeeze(),i=o.values.squeeze(),s=r.threshold,u=void 0===(c=r.maxResults)?20:c,f=r.iouThreshold,p=r.nmsActive,e.next=6,Promise.all([o.indices.data(),i.array(),a.array()]);case 6:return h=(d=e.sent)[0],v=d[1],m=d[2],e.next=12,n.image.nonMaxSuppressionWithScoreAsync(a,i,u,f,s,p?1:0);case 12:return y=e.sent,e.next=15,y.selectedIndices.data();case 15:return x=e.sent,n.dispose([y.selectedIndices,y.selectedScores]),e.abrupt("return",{detections:x,maxIndices:h,scores:v,boxes:m});case 18:case"end":return e.stop()}}),e)})))).apply(this,arguments)}function g(e,t){return w.apply(this,arguments)}function w(){return(w=a(l.mark((function e(t,r){var n,o,a,i,s,c,u,f,p,d,h,v;return l.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,t.data();case 2:for(n=e.sent,o=[],a=0;a<n.length;a++)o.push({value:n[a],index:a});for(o.sort((function(e,t){return t.value-e.value})),i=new Float32Array(r.topK),s=new Int32Array(r.topK),c=0;c<r.topK;c++)i[c]=o[c].value,s[c]=o[c].index;for(u=r.threshold,p=void 0===(f=r.maxResults)?r.topK:f,d=[],h=0;h<p;h++)d.push(i[h]);return v=d.filter((function(e){return e>u})),e.abrupt("return",v);case 14:case"end":return e.stop()}}),e)})))).apply(this,arguments)}function k(e,t){return E.apply(this,arguments)}function E(){return(E=a(l.mark((function e(t,r){var o;return l.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return o=n.expandDims(t,0),e.next=3,r.executeAsync(o);case 3:return e.abrupt("return",e.sent);case 5:case"end":return e.stop()}}),e)})))).apply(this,arguments)}function S(e,t,r){return L.apply(this,arguments)}function L(){return(L=a(l.mark((function e(t,r,o){var a,i,s,c;return l.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return a=t.toFloat().div(255),i=a,t.shape[0]===o&&t.shape[1]===o||(i=n.image.resizeBilinear(a,[o,o],!0)),s=i.reshape([1,o,o,3]),c=r.predict(s),e.abrupt("return",c);case 6:case"end":return e.stop()}}),e)})))).apply(this,arguments)}function T(e,t){return I.apply(this,arguments)}function I(){return(I=a(l.mark((function e(t,r){var n,o;return l.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(void 0===r&&(r=y),"ssd"!==(null==(n=r)?void 0:n.modelType)){e.next=7;break}return e.next=4,x(t,i({},y,r));case 4:return e.abrupt("return",e.sent);case 7:if("pose"!==(null==(o=r)?void 0:o.modelType)){e.next=11;break}return e.abrupt("return",t[0]);case 11:return e.next=13,g(t,i({},y,r));case 13:return e.abrupt("return",e.sent);case 14:case"end":return e.stop()}}),e)})))).apply(this,arguments)}function O(e,t){return C.apply(this,arguments)}function C(){return(C=a(l.mark((function e(t,r){var n,o,a,i,s,c,u;return l.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(void 0===r&&(r=y),a=r.labels,"ssd"!==(null==(n=r)?void 0:n.modelType)){e.next=8;break}return i=t.maxIndices,s=t.scores,c=Array.from(t.detections).map((function(e,t){return{class:t,classLabel:a?a[i[e]]:"class "+t,score:s[e]}})),e.abrupt("return",c);case 8:if("pose"!==(null==(o=r)?void 0:o.modelType)){e.next=12;break}return e.abrupt("return",t);case 12:return u=t.map((function(e,t){return{class:t,classLabel:a?a[t]:"class "+t,score:e}})),e.abrupt("return",u);case 14:case"end":return e.stop()}}),e)})))).apply(this,arguments)}var j={modelType:"ssd",threshold:.4,maxResults:20,iouThreshold:.5,nmsActive:!0,topK:5},R=function(e){var t=e.devices,n=t&&t.map((function(e){return r.createElement("option",{key:e.deviceId,value:e.deviceId},e.label)}));return r.createElement("div",null,r.createElement("select",{onChange:function(t){return e.onChange(t.target.value)},value:e.select},r.createElement("option",{disabled:!!e.select,value:"None"},"Choose a Camera"),n))};function A(e){return e?{width:e.offsetWidth,height:e.offsetHeight}:{}}var P={modelType:"ssd",threshold:.4,maxResults:20,iouThreshold:.5,nmsActive:!0,topK:5},D={modelType:"ssd",threshold:.4,maxResults:20,iouThreshold:.5,nmsActive:!0,topK:5},F=!1;exports.AILabImage=function(e){var o,s,c,u,f=e.model,p=e.modelConfig,v=e.ObjectDetectionUI,y=void 0===v?m:v,x=e.onInference,b=e.perf,g=e.perfCallback,w=e.src,E=e.size,L=void 0===E?224:E,I=e.visual,C=e.displaySize,R=e.style,A=t.useState(!1),P=A[0],D=A[1],F=t.useRef(null),z=t.useState(0),_=z[0],M=z[1],B=t.useState(),N=B[0],K=B[1],W=t.useState({}),U=W[0],q=W[1],G=t.useState(),H=G[0],Y=G[1],V=function(){var e=a(l.mark((function e(t){var r,o;return l.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(r=n.browser.fromPixels(F.current),"ssd"!==(null==p?void 0:p.modelType)){e.next=9;break}return H&&n.dispose([H[0],H[1]]),e.next=6,k(r,t);case 6:o=e.sent,e.next=19;break;case 9:if("pose"!==(null==p?void 0:p.modelType)){e.next=15;break}return e.next=12,t.estimatePoses(r,{maxPoses:1,flipHorizontal:!1});case 12:o=e.sent,e.next=19;break;case 15:return H&&n.dispose(H),e.next=18,S(r,t,L);case 18:o=e.sent;case 19:Y(o);case 20:case"end":return e.stop()}}),e)})));return function(t){return e.apply(this,arguments)}}();return t.useEffect((function(){n.ready().then((function(){D(!0)}))}),[]),t.useEffect((function(){var e=function(){var e=a(l.mark((function e(){var t;return l.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(!b&&!g){e.next=8;break}return e.next=3,d(a(l.mark((function e(){return l.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,V(f);case 2:case"end":return e.stop()}}),e)}))));case 3:t=e.sent,b&&K(t),g&&g(t),e.next=10;break;case 8:return e.next=10,V(f);case 10:case"end":return e.stop()}}),e)})));return function(){return e.apply(this,arguments)}}();if(P){var t=F.current;null!=t&&t.complete?e():t.onload=e}}),[w,P]),t.useEffect((function(){a(l.mark((function e(){var t,r;return l.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(!H){e.next=9;break}return e.next=3,T(H,p);case 3:return t=e.sent,e.next=6,O(t,p);case 6:r=e.sent,q(t),null==x||x(r);case 9:case"end":return e.stop()}}),e)})))()}),[p,H]),r.createElement("div",{style:R},r.createElement("div",{style:{position:"relative"}},b&&N&&r.createElement("div",{style:{position:"absolute",left:0,right:0,bottom:0}},r.createElement(h,Object.assign({},N,{drawingTime:_}))),r.createElement("img",{ref:F,src:w,height:"max"===C?"100%":void 0,width:"max"===C?"100%":void 0}),I&&r.createElement(y,{detectionResults:U,height:null!=(o=null==(s=F.current)?void 0:s.offsetHeight)?o:0,modelConfig:i({},j,p),onDrawComplete:function(e){_||M(e)},width:null!=(c=null==(u=F.current)?void 0:u.offsetWidth)?c:0})))},exports.AILabLocalVideo=function(e){var o,s,c,u,f=e.model,p=e.modelConfig,v=e.ObjectDetectionUI,y=void 0===v?m:v,x=e.onInference,b=e.perf,g=e.perfCallback,w=e.size,E=void 0===w?224:w,L=e.src,I=e.visual,C=e.displaySize,j=e.style,R=t.useState(!1),A=R[0],P=R[1],z=t.useState(),_=z[0],M=z[1],B=t.useState(0),N=B[0],K=B[1],W=t.useRef(null),U=t.useState({}),q=U[0],G=U[1],H=t.useState(),Y=H[0],V=H[1],$=t.useRef({lastTensor:-1,fps:0,calculateFps:function(){return Math.round(100*$.current.fps)/100}});function J(e){return Q.apply(this,arguments)}function Q(){return(Q=a(l.mark((function e(t){var r,o;return l.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(!(!W.current||F||W.current.readyState<2)){e.next=3;break}return requestAnimationFrame((function(){return J(t)})),e.abrupt("return");case 3:if(F=!0,"ssd"!==(null==p?void 0:p.modelType)){e.next=13;break}return r=n.browser.fromPixels(W.current),Y&&n.dispose([Y[0],Y[1]]),e.next=9,k(r,t);case 9:V(e.sent),e.next=19;break;case 13:return o=n.browser.fromPixels(W.current),Y&&n.dispose(Y),e.next=17,S(o,t,E);case 17:V(e.sent);case 19:F=!1;case 20:case"end":return e.stop()}}),e)})))).apply(this,arguments)}function X(){if(-1!==$.current.lastTensor){var e=performance.now()-$.current.lastTensor;$.current.fps=1e3/e}$.current.lastTensor=performance.now()}function Z(){return ee.apply(this,arguments)}function ee(){return(ee=a(l.mark((function e(){var t;return l.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(!F){e.next=2;break}return e.abrupt("return");case 2:if(console.log("calling runInference"),!b&&!g){e.next=12;break}return X(),e.next=7,d(a(l.mark((function e(){return l.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,J(f);case 2:case"end":return e.stop()}}),e)}))));case 7:t=e.sent,b&&M(t),g&&g(t),e.next=14;break;case 12:return e.next=14,J(f);case 14:!1===W.current.paused&&requestAnimationFrame(Z);case 15:case"end":return e.stop()}}),e)})))).apply(this,arguments)}return t.useEffect((function(){n.ready().then((function(){P(!0)}))}),[]),t.useEffect((function(){a(l.mark((function e(){var t,r;return l.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(!Y){e.next=9;break}return e.next=3,T(Y,p);case 3:return t=e.sent,e.next=6,O(t,p);case 6:r=e.sent,G(t),null==x||x(r);case 9:case"end":return e.stop()}}),e)})))()}),[p,Y]),r.createElement("div",{style:j},r.createElement("div",{style:{position:"relative"}},b&&_&&!!N&&r.createElement("div",{style:{position:"absolute",left:0,right:0,bottom:0}},r.createElement(h,Object.assign({},_,{drawingTime:N,fps:$.current.calculateFps()}))),I&&r.createElement(y,{detectionResults:q,height:null!=(o=null==(s=W.current)?void 0:s.offsetHeight)?o:0,modelConfig:i({},D,p),onDrawComplete:function(e){N||K(e)},width:null!=(c=null==(u=W.current)?void 0:u.offsetWidth)?c:0}),r.createElement("video",{crossOrigin:"anonymous",id:"video",src:L,ref:W,width:"max"===C?"100%":void 0,height:"max"===C?"100%":void 0,controls:!0,onEnded:function(){W.current&&(W.current.pause(),M(void 0))},onPause:function(){$.current.lastTensor=-1},onPlay:function(){A&&Z()},muted:!0})))},exports.AILabObjectDetectionUI=m,exports.AILabWebCam=function(e){var o,s,c,u,f=e.model,p=e.modelConfig,v=e.ObjectDetectionUI,y=void 0===v?m:v,x=e.onInference,b=e.perf,g=e.perfCallback,w=e.size,E=void 0===w?224:w,L=e.visual,I=e.displaySize,C=e.active,j=void 0===C||C,D=e.style,F=t.useRef(null),z=t.useRef(null),_=t.useRef(null),M=t.useState(!1),B=M[0],N=M[1],K=t.useState(null),W=K[0],U=K[1],q=t.useState(localStorage.getItem("currentDevice")||""),G=q[0],H=q[1],Y=t.useState(),V=Y[0],$=Y[1],J=t.useState(0),Q=J[0],X=J[1],Z=t.useState({}),ee=Z[0],te=Z[1],re=t.useState(),ne=re[0],oe=re[1];function ae(e,t){return ie.apply(this,arguments)}function ie(){return(ie=a(l.mark((function e(t,r){var o;return l.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if("ssd"!==(null==p?void 0:p.modelType)){e.next=7;break}return ne&&n.dispose([ne[0],ne[1]]),e.next=4,k(t,r);case 4:o=e.sent,e.next=17;break;case 7:if("pose"!==(null==p?void 0:p.modelType)){e.next=13;break}return e.next=10,r.estimatePoses(t,{maxPoses:1,flipHorizontal:!1});case 10:o=e.sent,e.next=17;break;case 13:return ne&&n.dispose(ne),e.next=16,S(t,r,E);case 16:o=e.sent;case 17:oe(o);case 18:case"end":return e.stop()}}),e)})))).apply(this,arguments)}function se(e){return ce.apply(this,arguments)}function ce(){return(ce=a(l.mark((function e(t){var r,n;return l.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(!z.current){e.next=2;break}return e.abrupt("return");case 2:return e.next=4,le();case 4:return r={deviceId:t?{exact:t}:void 0,width:{ideal:ye,max:ye},height:{ideal:ve,max:ve},facingMode:"user"},e.prev=6,e.next=9,navigator.mediaDevices.getUserMedia({audio:!1,video:r});case 9:z.current=n=e.sent,"srcObject"in F.current?F.current.srcObject=n:F.current.src=window.URL.createObjectURL(n),e.next=19;break;case 14:e.prev=14,e.t0=e.catch(6),localStorage.clear(),alert("Something went wrong for this device! Please change browsers, try again, or contribute to the site's open source!"),console.log(e.t0);case 19:case"end":return e.stop()}}),e,null,[[6,14]])})))).apply(this,arguments)}function ue(){var e,t;null==(e=z.current)||e.getTracks().forEach((function(e){e.stop()})),F.current&&(F.current.srcObject=null),z.current=null,null==(t=_.current)||t.stop()}function le(){return fe.apply(this,arguments)}function fe(){return(fe=a(l.mark((function e(){var t;return l.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,navigator.mediaDevices.enumerateDevices();case 2:t=e.sent.filter((function(e){return"videoinput"===e.kind})),U(t);case 5:case"end":return e.stop()}}),e)})))).apply(this,arguments)}function pe(){return(pe=a(l.mark((function e(t){return l.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:H(t),localStorage.setItem("currentDevice",t),ue(),se(t);case 4:case"end":return e.stop()}}),e)})))).apply(this,arguments)}t.useEffect((function(){n.ready().then((function(){N(!0)}))}),[]),t.useEffect((function(){var e=!0,t=function(){var t=a(l.mark((function t(){var r,o,i;return l.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return o=function(){return(o=a(l.mark((function e(){var t;return l.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(_.current){e.next=2;break}return e.abrupt("return");case 2:return e.next=4,_.current.capture();case 4:return t=e.sent,e.next=7,ae(t,f);case 7:case"end":return e.stop()}}),e)})))).apply(this,arguments)},r=function(){return o.apply(this,arguments)},t.next=4,n.data.webcam(F.current);case 4:if(_.current=t.sent,!b&&!g){t.next=17;break}case 6:if(!z.current||!j){t.next=15;break}if(!e){t.next=13;break}return t.next=10,d(r);case 10:i=t.sent,b&&$(i),g&&g(i);case 13:t.next=6;break;case 15:t.next=22;break;case 17:if(!z.current||!j){t.next=22;break}return t.next=20,r();case 20:t.next=17;break;case 22:case"end":return t.stop()}}),t)})));return function(){return t.apply(this,arguments)}}();return B&&se(G).then((function(){t()})),function(){ue(),e=!1}}),[B]),t.useEffect((function(){a(l.mark((function e(){var t,r;return l.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(!ne){e.next=9;break}return e.next=3,T(ne,p);case 3:return t=e.sent,e.next=6,O(t,p);case 6:r=e.sent,te(t),null==x||x(r);case 9:case"end":return e.stop()}}),e)})))()}),[p,ne]);var de=function(e){var r=t.useState(A(e.current)),n=r[0],o=r[1];function a(){e&&e.current&&o(A(e.current))}return t.useLayoutEffect((function(){return a(),window.addEventListener("resize",a),function(){window.removeEventListener("resize",a)}}),[]),n}(F),he=de.height,ve=void 0===he?0:he,me=de.width,ye=void 0===me?0:me;return r.createElement("div",{style:D},r.createElement("div",{style:{position:"relative"}},b&&V&&!!Q&&r.createElement("div",{style:{position:"absolute",left:0,right:0,bottom:0}},r.createElement(h,Object.assign({},V,{drawingTime:Q}))),r.createElement("video",{ref:F,autoPlay:!0,height:"max"===I?"100%":"768px",width:"max"===I?"100%":"1024px"}),L&&r.createElement(y,{detectionResults:ee,height:null!=(o=null==(s=F.current)?void 0:s.offsetHeight)?o:0,modelConfig:i({},P,p),onDrawComplete:function(e){Q||X(e)},width:null!=(c=null==(u=F.current)?void 0:u.offsetWidth)?c:0})),r.createElement("div",null,r.createElement(R,{select:G,devices:W,onChange:function(e){return pe.apply(this,arguments)}}),r.createElement("button",{onClick:ue},"Stop WebCam")))},exports.CLASSES=["person","bicycle","car","motorcycle","airplane","bus","train","truck","boat","traffic light","fire hydrant","unused","stop sign","parking meter","bench","bird","cat","dog","horse","sheep","cow","elephant","bear","zebra","giraffe","unused","backpack","umbrella","unused","unused","handbag","tie","suitcase","frisbee","skis","snowboard","sports ball","kite","baseball bat","baseball glove","skateboard","surfboard","tennis racket","bottle","unused","wine glass","cup","fork","knife","spoon","bowl","banana","apple","sandwich","orange","broccoli","carrot","hot dog","pizza","donut","cake","chair","couch","potted plant","bed","unused","dining table","unused","unused","toilet","unused","tv","laptop","mouse","remote","keyboard","cell phone","microwave","oven","toaster","sink","refrigerator","unused","book","clock","vase","scissors","teddy bear","hair drier","toothbrush"],exports.SimpleObjectDetectionUI=function(e){var o=e.detectionResults,i=e.height,s=e.modelConfig,u=e.onDrawComplete,f=e.width,p=t.useRef(null);function d(){return h.apply(this,arguments)}function h(){return(h=a(l.mark((function e(){var t,r,n,a,s,d,h,v,m;return l.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:for(t=o.detections,r=o.boxes,a=null==(n=p.current)?void 0:n.getContext("2d"),n.width=f,n.height=i,a.font="16px sans-serif",a.textBaseline="top",s=performance.now(),d=c(t);!(h=d()).done;)v=h.value,a.strokeStyle="#F00",a.lineWidth=4,a.globalCompositeOperation="destination-over",a.strokeRect((m=r[v])[1]>0?m[1]*f:0,m[0]>0?m[0]*i:0,(m[3]-m[1])*f,(m[2]-m[0])*i),null==u||u(performance.now()-s);case 9:case"end":return e.stop()}}),e)})))).apply(this,arguments)}return t.useEffect((function(){n.ready().then(d)}),[o,i,s,f]),r.createElement("canvas",{ref:p,style:{position:"absolute",left:0,top:0,height:i,width:f}})},exports.classificationModelDetection=g,exports.getInferenceData=O,exports.getModelDetections=T,exports.predictClassification=S,exports.predictSSD=k,exports.ssdModelDetection=x;
//# sourceMappingURL=ai-lab.cjs.production.min.js.map
/// <reference types="react" />
import { VideoProps } from '../../types';
export declare const AILabWebCam: ({ model, modelConfig, ObjectDetectionUI, onInference, perf, perfCallback, size, visual, displaySize, style, }: VideoProps) => JSX.Element;
export declare const AILabWebCam: ({ model, modelConfig, ObjectDetectionUI, onInference, perf, perfCallback, size, visual, displaySize, active, style, }: VideoProps) => JSX.Element;

@@ -29,2 +29,3 @@ import * as tf from '@tensorflow/tfjs';

src?: string;
active?: boolean;
visual?: boolean;

@@ -31,0 +32,0 @@ displaySize?: 'content' | 'max';

{
"name": "ai-lab",
"version": "0.0.2-alpha.0",
"version": "0.0.2-alpha.1",
"description": "A set of components for AI in React",

@@ -11,2 +11,16 @@ "main": "dist/index.js",

],
"repository": {
"type": "git",
"url": "git+https://github.com/infinitered/ai-lab.git"
},
"keywords": [
"AI",
"React",
"tensorflow.js",
"tensorflow",
"machine learning",
"ai",
"react",
"ai-lab"
],
"author": "Gant Laborde",

@@ -13,0 +27,0 @@ "license": "MIT",

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc