Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
rsmets committed Nov 24, 2023
1 parent be3b3b7 commit dfa95be
Showing 1 changed file with 20 additions and 12 deletions.
32 changes: 20 additions & 12 deletions narrator.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,20 @@

from elevenlabs import generate, play, set_api_key, stream
from openai import OpenAI
from pynput import ( # Use pynput to listen for keypresses instead of native keyboard module which was requiring admin privileges
from pynput import ( # Using pynput to listen for a keypress instead of native keyboard module which was requiring admin privileges
keyboard,
)

client = OpenAI()

set_api_key(os.environ.get("ELEVENLABS_API_KEY"))

# Initializes the variables based their respective environment variable values, defaulting to false
isStreaming = os.environ.get("ELEVENLABS_STREAMING", "false") == "true"
isPhotoBooth = os.environ.get("PHOTOBOOTH_MODE", "false") == "true"

script = []
narrator = "Sir David Attenborough"


def on_press(key):
Expand All @@ -35,12 +40,6 @@ def on_release(key):
listener.start()


# This code initializes the variable 'isStreaming' based on the value of the environment variable 'ELEVENLABS_STREAMIMAGES'.
# If the value of 'ELEVENLABS_STREAMIMAGES' is "true", then 'isStreaming' is set to True.
# Otherwise, 'isStreaming' is set to False.
isStreaming = os.environ.get("ELEVENLABS_STREAMING", "false") == "true"


def encode_image(image_path):
while True:
try:
Expand Down Expand Up @@ -86,7 +85,7 @@ def generate_new_line(base64_image):
"content": [
{
"type": "text",
"text": "Describe this image as if you are David Attenborough",
"text": f"Describe this image as if you are {narrator}",
},
{
"type": "image_url",
Expand All @@ -103,8 +102,8 @@ def analyze_image(base64_image, script):
messages=[
{
"role": "system",
"content": """
You are Sir David Attenborough. Narrate the picture of the human as if it is a nature documentary.
"content": f"""
You are {narrator}. Narrate the picture of the human as if it is a nature documentary.
Make it snarky and funny. Don't repeat yourself. Make it short. If I do anything remotely interesting, make a big deal about it!
""",
},
Expand All @@ -127,7 +126,7 @@ def _main():
base64_image = encode_image(image_path)

# analyze posture
print("👀 David is watching...")
print(f"👀 {narrator} is watching...")
analysis = analyze_image(base64_image, script=script)

print("🎙️ David says:")
Expand All @@ -140,8 +139,17 @@ def _main():

def main():
while True:
pass
if isPhotoBooth:
pass
else:
_main()

# wait for 5 seconds
time.sleep(5)


if isPhotoBooth:
print(f"Press the spacebar to trigger {narrator}")

if __name__ == "__main__":
main()

0 comments on commit dfa95be

Please sign in to comment.