Skip to content

Commit

Permalink
go back to using @DataClass since they can be inspected
Browse files Browse the repository at this point in the history
  • Loading branch information
aconchillo committed May 13, 2024
1 parent 6c06fb8 commit b254525
Show file tree
Hide file tree
Showing 25 changed files with 213 additions and 397 deletions.
17 changes: 5 additions & 12 deletions examples/foundational/05-sync-speech-and-image.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import os
import sys

import daily
from dataclasses import dataclass

from pipecat.frames.frames import (
AppFrame,
Expand Down Expand Up @@ -44,20 +44,13 @@
logger.add(sys.stderr, level="DEBUG")


@dataclass
class MonthFrame(AppFrame):
def __init__(self, month):
super().__init__()
self.metadata["month"] = month

@ property
def month(self) -> str:
return self.metadata["month"]
month: str

def __str__(self):
return f"{self.name}(month: {self.month})"

month: str


class MonthPrepender(FrameProcessor):
def __init__(self):
Expand All @@ -69,7 +62,7 @@ async def process_frame(self, frame: Frame, direction: FrameDirection):
if isinstance(frame, MonthFrame):
self.most_recent_month = frame.month
elif self.prepend_to_next_text_frame and isinstance(frame, TextFrame):
await self.push_frame(TextFrame(f"{self.most_recent_month}: {frame.data}"))
await self.push_frame(TextFrame(f"{self.most_recent_month}: {frame.text}"))
self.prepend_to_next_text_frame = False
elif isinstance(frame, LLMResponseStartFrame):
self.prepend_to_next_text_frame = True
Expand Down Expand Up @@ -152,7 +145,7 @@ async def main(room_url):
"content": f"Describe a nature photograph suitable for use in a calendar, for the month of {month}. Include only the image description with no preamble. Limit the description to one sentence, please.",
}
]
frames.append(MonthFrame(month))
frames.append(MonthFrame(month=month))
frames.append(LLMMessagesFrame(messages))

frames.append(EndFrame())
Expand Down
2 changes: 1 addition & 1 deletion examples/foundational/05a-local-sync-speech-and-image.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ def __init__(self):

async def process_frame(self, frame: Frame, direction: FrameDirection):
if isinstance(frame, AudioRawFrame):
self.audio.extend(frame.data)
self.audio.extend(frame.audio)
self.frame = AudioRawFrame(
bytes(self.audio), frame.sample_rate, frame.num_channels)

Expand Down
4 changes: 2 additions & 2 deletions examples/foundational/06a-image-sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,9 @@ def __init__(self, speaking_path: str, waiting_path: str):

async def process_frame(self, frame: Frame, direction: FrameDirection):
if not isinstance(frame, SystemFrame):
await self.push_frame(ImageRawFrame(self._speaking_image_bytes, (1024, 1024), self._speaking_image_format))
await self.push_frame(ImageRawFrame(image=self._speaking_image_bytes, size=(1024, 1024), format=self._speaking_image_format))
await self.push_frame(frame)
await self.push_frame(ImageRawFrame(self._waiting_image_bytes, (1024, 1024), self._waiting_image_format))
await self.push_frame(ImageRawFrame(image=self._waiting_image_bytes, size=(1024, 1024), format=self._waiting_image_format))
else:
await self.push_frame(frame)

Expand Down
2 changes: 1 addition & 1 deletion examples/foundational/08-bots-arguing.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ async def get_text_and_audio(messages) -> Tuple[str, bytearray]:
if isinstance(frame, TextFrame):
message += frame.text
elif isinstance(frame, AudioFrame):
all_audio.extend(frame.data)
all_audio.extend(frame.audio)

return (message, all_audio)

Expand Down
4 changes: 2 additions & 2 deletions examples/foundational/10-wake-word.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@
filename = os.path.splitext(os.path.basename(full_path))[0]
# Open the image and convert it to bytes
with Image.open(full_path) as img:
sprites[file] = ImageRawFrame(img.tobytes(), img.size, img.format)
sprites[file] = ImageRawFrame(image=img.tobytes(), size=img.size, format=img.format)

# When the bot isn't talking, show a static image of the cat listening
quiet_frame = sprites["sc-listen-1.png"]
Expand Down Expand Up @@ -99,7 +99,7 @@ async def process_frame(self, frame: Frame, direction: FrameDirection):

# TODO: split up transcription by participant
if isinstance(frame, TranscriptionFrame):
content = frame.data
content = frame.text
self._sentence += content
if self._sentence.endswith((".", "?", "!")):
if any(name in self._sentence for name in self._names):
Expand Down
Loading

0 comments on commit b254525

Please sign in to comment.