npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

vytal

v0.9.2

Published

Calibration

Downloads

53

Readme

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.