Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update assistant.py #6

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 16 additions & 16 deletions assistant.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,12 @@ def update(self):
while self.running:
_, frame = self.stream.read()

self.lock.acquire()
self.frame = frame
self.lock.release()
with self.lock:
self.frame = frame

def read(self, encode=False):
self.lock.acquire()
frame = self.frame.copy()
self.lock.release()
with self.lock:
frame = self.frame.copy()

if encode:
_, buffer = imencode(".jpeg", frame)
Expand Down Expand Up @@ -94,6 +92,7 @@ def _tts(self, response):
) as stream:
for chunk in stream.iter_bytes(chunk_size=1024):
player.write(chunk)
player.close()

def _create_inference_chain(self, model):
SYSTEM_PROMPT = """
Expand Down Expand Up @@ -138,8 +137,8 @@ def _create_inference_chain(self, model):

model = ChatGoogleGenerativeAI(model="gemini-1.5-flash-latest")

# You can use OpenAI's GPT-4o model instead of Gemini Flash
# by uncommenting the following line:
# Możesz użyć OpenAI GPT-4o zamiast Gemini Flash
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's keep comments in English

# odkomentowując następującą linię:
# model = ChatOpenAI(model="gpt-4o")

assistant = Assistant(model)
Expand All @@ -161,11 +160,12 @@ def audio_callback(recognizer, audio):

stop_listening = recognizer.listen_in_background(microphone, audio_callback)

while True:
cv2.imshow("webcam", webcam_stream.read())
if cv2.waitKey(1) in [27, ord("q")]:
break

webcam_stream.stop()
cv2.destroyAllWindows()
stop_listening(wait_for_stop=False)
try:
while True:
cv2.imshow("webcam", webcam_stream.read())
if cv2.waitKey(1) in [27, ord("q")]:
break
finally:
webcam_stream.stop()
cv2.destroyAllWindows()
stop_listening(wait_for_stop=False)