Get detection working

This commit is contained in:
James Hush
2025-05-25 11:02:14 +08:00
parent 9ac077a6b2
commit 887cdb4057
2 changed files with 47 additions and 13 deletions

View File

@@ -5,6 +5,7 @@
# #
import argparse import argparse
from typing import Optional
from dotenv import load_dotenv from dotenv import load_dotenv
from loguru import logger from loguru import logger
@@ -12,6 +13,8 @@ from loguru import logger
from pipecat.frames.frames import ( from pipecat.frames.frames import (
EndFrame, EndFrame,
Frame, Frame,
InputImageRawFrame,
OutputImageRawFrame,
TextFrame, TextFrame,
TTSTextFrame, TTSTextFrame,
UserImageRequestFrame, UserImageRequestFrame,
@@ -34,26 +37,41 @@ from pipecat.transports.network.webrtc_connection import SmallWebRTCConnection
load_dotenv(override=True) load_dotenv(override=True)
class UserImageRequester(FrameProcessor): class DebugProcessor(FrameProcessor):
def __init__(self): def __init__(self):
super().__init__() super().__init__()
self.participant_id = None
def set_participant_id(self, participant_id: str):
self.participant_id = participant_id
async def process_frame(self, frame: Frame, direction: FrameDirection): async def process_frame(self, frame: Frame, direction: FrameDirection):
await super().process_frame(frame, direction) await super().process_frame(frame, direction)
if self.participant_id and isinstance(frame, TextFrame): if isinstance(frame, TextFrame):
await self.push_frame( logger.info(f"DebugProcessor received text: {frame.text}")
UserImageRequestFrame(self.participant_id), FrameDirection.UPSTREAM elif isinstance(frame, EndFrame):
logger.info("DebugProcessor received end frame")
await self.push_frame(frame, direction)
class UserImageRequester(FrameProcessor):
def __init__(self, participant_id: Optional[str] = None):
super().__init__()
async def process_frame(self, frame: Frame, direction: FrameDirection):
await super().process_frame(frame, direction)
if isinstance(frame, OutputImageRawFrame):
await self.push_frame(frame)
# logger.info(f"UserImageRequester received image frame with size: {frame.size}")
text_frame = TextFrame(
"Are there people in the bottom right corner of the image? Only answer with YES or NO."
) )
await self.push_frame( await self.push_frame(text_frame)
TextFrame( input_frame = InputImageRawFrame(
"Is there a person wearing a blue shirt in this image? Only answer with YES or NO." image=frame.image,
) size=frame.size,
format=frame.format,
) )
await self.push_frame(input_frame)
else: else:
await self.push_frame(frame, direction) await self.push_frame(frame, direction)
@@ -85,11 +103,13 @@ async def run_bot(webrtc_connection: SmallWebRTCConnection, args: argparse.Names
ir = UserImageRequester() ir = UserImageRequester()
va = VisionImageFrameAggregator() va = VisionImageFrameAggregator()
debug = DebugProcessor()
pipeline = Pipeline( pipeline = Pipeline(
[ [
gst, # GStreamer file source gst, # GStreamer file source
ir, ir,
# debug,
va, va,
moondream, moondream,
# alert_processor, # Send an email alert or something if the door is open # alert_processor, # Send an email alert or something if the door is open
@@ -102,13 +122,26 @@ async def run_bot(webrtc_connection: SmallWebRTCConnection, args: argparse.Names
observers=[ observers=[
DebugLogObserver( DebugLogObserver(
frame_types={ frame_types={
TextFrame: None, # TextFrame: None,
# InputImageRawFrame: None,
EndFrame: None, EndFrame: None,
} }
), ),
], ],
) )
@transport.event_handler("on_client_connected")
async def on_client_connected(transport, client):
logger.info(f"Client connected: {client}")
await task.queue_frames(
[
TextFrame(
"Are there people in the bottom right corner of the image? Only answer with YES or NO."
)
]
)
runner = PipelineRunner(handle_sigint=False) runner = PipelineRunner(handle_sigint=False)
await runner.run(task) await runner.run(task)

View File

@@ -81,5 +81,6 @@ class MoondreamService(VisionService):
return description return description
description = await asyncio.to_thread(get_image_description, frame) description = await asyncio.to_thread(get_image_description, frame)
logger.info(f"Image description: {description}")
yield TextFrame(text=description) yield TextFrame(text=description)