Skip to content

Commit

Permalink
fix: lazy import mediapipe
Browse files Browse the repository at this point in the history
  • Loading branch information
CodyJasonBennett committed Oct 16, 2023
1 parent 8a64fb7 commit 85c49f5
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/core/FaceControls.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import {
useContext,
} from 'react'
import { useFrame, useThree } from '@react-three/fiber'
import { FaceLandmarkerResult } from '@mediapipe/tasks-vision'
import type { FaceLandmarkerResult } from '@mediapipe/tasks-vision'
import { easing } from 'maath'
import { suspend, clear } from 'suspend-react'

Expand Down
8 changes: 4 additions & 4 deletions src/core/FaceLandmarker.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* eslint react-hooks/exhaustive-deps: 1 */
import * as React from 'react'
import { createContext, ReactNode, useContext, useEffect } from 'react'
import { FilesetResolver, FaceLandmarker as FaceLandmarkerImpl, FaceLandmarkerOptions } from '@mediapipe/tasks-vision'
import type { FaceLandmarker as FaceLandmarkerImpl, FaceLandmarkerOptions } from '@mediapipe/tasks-vision'
import { clear, suspend } from 'suspend-react'

const FaceLandmarkerContext = /* @__PURE__ */ createContext({} as FaceLandmarkerImpl | undefined)
Expand Down Expand Up @@ -34,9 +34,9 @@ export function FaceLandmarker({
const opts = JSON.stringify(options)

const faceLandmarker = suspend(async () => {
return await FilesetResolver.forVisionTasks(basePath).then((vision) =>
FaceLandmarkerImpl.createFromOptions(vision, options)
)
const { FilesetResolver, FaceLandmarker } = await import('@mediapipe/tasks-vision')
const vision = await FilesetResolver.forVisionTasks(basePath)
return FaceLandmarker.createFromOptions(vision, options)
}, [basePath, opts])

useEffect(() => {
Expand Down

0 comments on commit 85c49f5

Please sign in to comment.