0.9.2 • Published 11 months ago

vytal v0.9.2

Weekly downloads
-
License
MIT
Repository
github
Last release
11 months ago

Vytal

An accurate gaze-tracking API with real time predictions and inferencing.

Installation

Using NPM:

$ npm install vytal

Using yarn:

$ yarn add vytal

Go to our API portal{:target="_blank"} to get credits to attain accurate gaze coordinates before you get started.

This package requires TailwindCSS{:target="_blank"}. Please install and setup Tailwind before using the package.

Real Time Predictions Example

import React, { useState, useRef, useEffect } from 'react';
import realTimePreds from 'vytal/dist/main';
import RealTimeCalibration from "vytal/dist/main";

const RealTimePredictions = () => {
  const apiKey = 'sk-...';
  const videoRef = useRef(null);
  const [predictions, setPredictions] = useState([]);
  const [calibMatrix, setCalibMatrix] = useState(null);
  const [windowInformation, setWindowInformation] = useState(null)

  const handleMatrix = (matrix) => {
    setCalibMatrix(matrix);
  };

  useEffect(() => {
    setWindowInformation(window);
  }, []);

  useEffect(() => {
    const startVideoStream = async () => {
      try {
        const stream = await navigator.mediaDevices.getUserMedia({ video: true });
        if (videoRef.current) {
          videoRef.current.srcObject = stream;
          await videoRef.current.play();
        }
      } catch (err) {
        console.error("Error accessing camera:", err);
      }
    };

    startVideoStream();

    return () => {
      if (videoRef.current && videoRef.current.srcObject) {
        const tracks = videoRef.current.srcObject.getTracks();
        tracks.forEach(track => track.stop());
      }
    };
  }, []);

  useEffect(() => {
    if (videoRef.current && calibrationMatrix) {
      const { predictions } = realTimePreds(apiKey, calibrationMatrix, videoRef);

      const predictionWatcher = () => {
        setPredictions(predictions);
      };

      predictionWatcher();
      const watcherInterval = setInterval(predictionWatcher, 100);

      return () => {
        clearInterval(watcherInterval);
      };
    }
  }, [apiKey, calibrationMatrix]);

  return (
    <div>
      {calibMat ? (
        <>
          <video ref={videoRef} style={{ display: 'none' }} />
          <ul>
            {predictions.map((prediction, index) => (
              <li key={index}>Prediction: {JSON.stringify(prediction)}</li>
            ))}
          </ul>
          <button onClick={startStream}>Start Predictions</button>
        </>
      ) : (
        windowInformation && (
          <RealTimeCalibration
            window={windowInformation}
            apiKey="sk-..."
            setCalibrationMatrix={handleMatrix}
          />
        )
      )}
    </div>
  );
};

export default RealTimePredictions;

Inferencing Example

import Calibration from "vytal/dist/main";
import { useEffect, useState } from "react";

export default function VideoInferencing() {
  const [windowInformation, setWindowInformation] = useState(null);
  const [calibMatrix, setCalibMatrix] = useState(null);

  useEffect(() => {
    setWindowInformation(window);
  }, []);

  const handleMatrix = (matrix) => {
    setCalibMatrix(matrix);
  };

  const handleInference = async () => {
    // Access user video stream (implementation omitted for brevity)
    const videoBlob = await getVideoBlobFromStream(); // Replace with your video capture logic

    try {
      const preds = await inference(videoBlob, apiKey, calibMatrix);
      setPredictions(preds);
    } catch (error) {
      console.error('Error during inference:', error);
    }
  };

  return (
    <div>
      {windowInformation && (
        <Calibration
          window={windowInformation}
          apiKey="sk-..."
          calibrationMatrix={handleMatrix}
        />
      )}
      {calibMatrix && (
          <button onClick={handleInference}>Get Predictions</button>
      )}
      {predictions && <pre>{JSON.stringify(predictions, null, 2)}</pre>}
    </div>
  );
}

Parameters

Calibration

  • window (object), required: information about the window of the user's currrent screen
  • apiKey (str), required: API key for calibration
  • calibrationMatrix (func), required: retrieve matrix from calibration to use for inferencing
  • redirect (str), optional: Link with where to redirect after calibration is complete. Default is "#"

Inference

  • videoBlob (Blob), required: information about the video that was recorded
  • apiKey (str), required: API key for inferencing
  • calibrationMat (str), required: calibration matrix string from Calibration to retrieve accurate inferences

Real Time Calibration

  • window (object), required: information about the window of the user's currrent screen
  • apiKey (str), required: API key for calibration
  • setCalibrationMatrix (func), required: retrieve matrix from calibration to use for inferencing

Real Time Predictions

  • apiKey (str), required: API key for real time predictions
  • calibMat (str), required: calibration matrix string from Calibration to retrieve accurate predications
  • feed (Video), required: information about the current stream

Error Handling

Any errors (e.g., API Key validation, model errors, and file input issues) will be in the console.

0.9.2

11 months ago

0.9.1

11 months ago

0.9.0

11 months ago

0.8.9

12 months ago

0.8.8

12 months ago

0.8.7

12 months ago

0.8.6

12 months ago

0.8.5

12 months ago

0.8.4

12 months ago

0.8.3

12 months ago

0.8.2

12 months ago

0.8.1

12 months ago

0.8.0

12 months ago

0.7.9

12 months ago

0.7.8

12 months ago

0.7.7

12 months ago

0.7.6

12 months ago

0.7.5

12 months ago

0.7.4

1 year ago

0.7.3

1 year ago

0.7.2

1 year ago

0.7.1

1 year ago

0.7.0

1 year ago

0.6.9

1 year ago

0.6.8

1 year ago

0.6.7

1 year ago

0.6.6

1 year ago

0.6.5

1 year ago

0.6.4

1 year ago

0.6.3

1 year ago

0.6.2

1 year ago

0.6.1

1 year ago

0.6.0

1 year ago

0.5.9

1 year ago

0.5.8

1 year ago

0.5.7

1 year ago

0.5.6

1 year ago

0.5.5

1 year ago

0.5.4

1 year ago

0.5.3

1 year ago

0.5.2

1 year ago

0.5.1

1 year ago

0.5.0

1 year ago

0.4.9

1 year ago

0.4.8

1 year ago

0.4.7

1 year ago

0.4.6

1 year ago

0.4.5

1 year ago

0.4.4

1 year ago

0.4.3

1 year ago

0.4.2

1 year ago

0.4.1

1 year ago

0.4.0

1 year ago

0.3.9

1 year ago

0.3.7

1 year ago

0.3.6

1 year ago

0.3.5

1 year ago

0.3.4

1 year ago

0.3.3

1 year ago

0.3.2

1 year ago

0.3.1

1 year ago

0.3.0

1 year ago

0.2.9

1 year ago

0.2.8

1 year ago

0.2.7

1 year ago

0.2.6

1 year ago

0.2.5

1 year ago

0.2.4

1 year ago

0.2.3

1 year ago

0.2.2

1 year ago

0.2.1

1 year ago

0.2.0

1 year ago

0.1.9

1 year ago

0.1.8

1 year ago

0.1.7

1 year ago

0.1.6

1 year ago

0.1.5

1 year ago

0.1.4

1 year ago

0.1.3

1 year ago

0.1.2

1 year ago

0.1.1

1 year ago

0.1.0

1 year ago