File size: 1,561 Bytes
357c750
 
 
 
 
 
 
3f09bdf
357c750
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
ffc2aa4
357c750
 
 
 
 
 
 
 
ffc2aa4
 
 
 
 
357c750
 
 
ffc2aa4
 
 
 
 
 
 
 
 
357c750
ffc2aa4
 
357c750
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
from dora import DoraStatus
import pyarrow as pa


import cv2

from idefics2_utils import ask_vlm
import pyttsx3


CAMERA_WIDTH = 960
CAMERA_HEIGHT = 540


FONT = cv2.FONT_HERSHEY_SIMPLEX


engine = pyttsx3.init("espeak")
voices = engine.getProperty("voices")
engine.setProperty("voice", voices[11].id)  # English


def speak(text):
    engine.say(text)
    engine.runAndWait()


class Operator:
    def __init__(self):
        self.instruction = "What is in the image?"
        self.last_message = ""
        self.image = None

    def on_event(
        self,
        dora_event,
        send_output,
    ) -> DoraStatus:
        if dora_event["type"] == "INPUT":
            if dora_event["id"] == "image":
                self.image = (
                    dora_event["value"]
                    .to_numpy()
                    .reshape((CAMERA_HEIGHT, CAMERA_WIDTH, 3))
                )
            elif dora_event["id"] == "instruction":
                self.instruction = dora_event["value"][0].as_py()
                print("instructions: ", self.instruction, flush=True)

                if self.image is not None:
                    output = ask_vlm(self.image, self.instruction)
                    speak(output)
                    print("response: ", output, flush=True)
                    send_output(
                        "assistant_message",
                        pa.array([output]),
                        dora_event["metadata"],
                    )

                    self.last_message = output
        return DoraStatus.CONTINUE