added web server

This commit is contained in:
Chad Bailey
2024-01-24 18:05:41 +00:00
parent 9bbd14d5e7
commit bc6849b255
9 changed files with 177 additions and 9 deletions

View File

@@ -20,6 +20,10 @@ class ImageQueueFrame(QueueFrame):
url: str | None
image: bytes
@dataclass()
class ImageListQueueFrame(QueueFrame):
images: list[bytes] | None
@dataclass()
class TextQueueFrame(QueueFrame):
text: str

View File

@@ -12,6 +12,7 @@ from dailyai.queue_frame import (
AudioQueueFrame,
EndStreamQueueFrame,
ImageQueueFrame,
ImageListQueueFrame,
QueueFrame,
StartStreamQueueFrame,
TranscriptionQueueFrame,
@@ -149,6 +150,7 @@ class DailyTransportService(EventHandler):
)
self.image: bytes | None = None
self.images: list[bytes] | None = None
self.camera_thread = Thread(target=self.run_camera, daemon=True)
self.camera_thread.start()
@@ -307,12 +309,22 @@ class DailyTransportService(EventHandler):
def set_image(self, image: bytes):
self.image: bytes | None = image
self.images: list[bytes] | None = None
def set_images(self, images: list[bytes], start_frame=0):
self.images: list[bytes] | None = images
self.image = None
self.current_frame = start_frame
def run_camera(self):
try:
while not self.stop_threads.is_set():
if self.image:
self.camera.write_frame(self.image)
if self.images:
this_frame = self.current_frame % len(self.images)
self.camera.write_frame(self.sprites[self.images[this_frame]])
self.current_frame = this_frame + 1
time.sleep(1.0 / 8) # 8 fps
except Exception as e:
@@ -354,6 +366,8 @@ class DailyTransportService(EventHandler):
b = b[l:]
elif isinstance(frame, ImageQueueFrame):
self.set_image(frame.image)
elif isinstance(frame, ImageListQueueFrame):
self.set_images(frame.images)
elif len(b):
self.mic.write_frames(bytes(b))
b = bytearray()

View File

@@ -8,6 +8,7 @@ from dailyai.services.daily_transport_service import DailyTransportService
from dailyai.services.azure_ai_services import AzureLLMService, AzureTTSService
from dailyai.services.elevenlabs_ai_service import ElevenLabsTTSService
from dailyai.services.fal_ai_services import FalImageGenService
from dailyai.services.open_ai_services import OpenAIImageGenService
from dailyai.queue_aggregators import LLMContextAggregator
from dailyai.queue_frame import LLMMessagesQueueFrame, QueueFrame, TextQueueFrame
from dailyai.services.ai_services import AIService
@@ -73,11 +74,12 @@ async def main(room_url:str, token):
)
async def make_cats():
imagegen = FalImageGenService(image_size="1024x1024")
imagegen = OpenAIImageGenService(image_size="1024x1024")
while True:
imagegen.run_to_queue(transport.send_queue, [TextQueueFrame("a golden kitty trophy, cartoon, colorful, detailed, 4k")])
await asyncio.sleep(60)
print("generating new image")
await imagegen.run_to_queue(transport.send_queue, [TextQueueFrame("a golden kitty trophy, cartoon, colorful, detailed, 4k")])
await asyncio.sleep(10)
transport.transcription_settings["extra"]["punctuate"] = True
await asyncio.gather(transport.run(), handle_transcriptions(), make_cats())
@@ -101,9 +103,9 @@ if __name__ == "__main__":
args, unknown = parser.parse_known_args()
# Create a meeting token for the given room with an expiration 5 hours in the future.
# Create a meeting token for the given room with an expiration 24 hours in the future.
room_name: str = urllib.parse.urlparse(args.url).path[1:]
expiration: float = time.time() + 60 * 60 * 5
expiration: float = time.time() + 60 * 60 * 24
res: requests.Response = requests.post(
f"https://api.daily.co/v1/meeting-tokens",

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.7 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.7 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.7 MiB