feat: grabs screenshot instead webcam

sarcastic technical lead prompt
This commit is contained in:
balint.lendvai 2023-11-16 11:42:58 +01:00
parent 4bab10462a
commit a032cea844
4 changed files with 32 additions and 46 deletions

2
.gitignore vendored
View File

@ -2,3 +2,5 @@
/venv
/frames
/narration
/screeshots
.vscode

View File

@ -1,5 +1,9 @@
# narrator
# sarcastic narrator
Sarcastic David Attenborough narrates what you are doing based on your screen
Forked from this project:
https://github.com/cbh123/narrator
David Attenborough narrates your life.
https://twitter.com/charliebholtz/status/1724815159590293764

View File

@ -1,46 +1,26 @@
import cv2
from PIL import ImageGrab
import os
import time
from PIL import Image
import numpy as np
# Folder
folder = "frames"
# Create a folder to store the screenshot if it doesn't exist
folder = "screenshots"
if not os.path.exists(folder):
os.makedirs(folder)
# Initialize the webcam
cap = cv2.VideoCapture(0)
# Constant filename for the screenshot
filename = os.path.join(folder, "screenshot.png")
# Check if the webcam is opened correctly
if not cap.isOpened():
raise IOError("Cannot open webcam")
# Wait for the camera to initialize and adjust light levels
time.sleep(2)
# Function to take a screenshot
def take_screenshot(filename):
# Capture the entire screen
screen = ImageGrab.grab()
# Save the image file
screen.save(filename)
try:
while True:
ret, frame = cap.read()
if ret:
# Convert the frame to a PIL image
pil_img = Image.fromarray(cv2.cvtColor(frame, cv2.COLOR_BGR2RGB))
# Resize the image
max_size = 250
ratio = max_size / max(pil_img.size)
new_size = tuple([int(x*ratio) for x in pil_img.size])
resized_img = pil_img.resize(new_size, Image.LANCZOS)
# Convert the PIL image back to an OpenCV image
frame = cv2.cvtColor(np.array(resized_img), cv2.COLOR_RGB2BGR)
# Save the frame as an image file
print("📸 Say cheese! Saving frame.")
path = f"{folder}/frame.jpg"
cv2.imwrite(path, frame)
else:
print("Failed to capture image")
# Wait for 2 seconds
time.sleep(2)
# Release the camera and close all windows
cap.release()
cv2.destroyAllWindows()
take_screenshot(filename)
print(f"Screenshot saved as {filename}")
time.sleep(5) # Wait for 5 seconds before taking the next screenshot
except KeyboardInterrupt:
print("Stopped taking screenshots")

View File

@ -24,7 +24,8 @@ def encode_image(image_path):
def play_audio(text):
audio = generate(text=text, voice="ENfvYmv6CRqDodDZTieQ", model="eleven_turbo_v2")
// voice param will be your Voice_id coming from the Elevenlabs API
audio = generate(text=text, voice="ELEVENLABS_SELECTED_VOICE_ID", model="eleven_turbo_v2")
unique_id = base64.urlsafe_b64encode(os.urandom(30)).decode("utf-8").rstrip("=")
dir_path = os.path.join("narration", unique_id)
@ -59,8 +60,7 @@ def analyze_image(base64_image, script):
{
"role": "system",
"content": """
You are Sir David Attenborough. 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!
You are a senior frontend technical lead whos task is to sarcastically review other programmers pure code snippets on screenshots you get. be short, harsh, and very sarcastic. Roast me in 5-8 sentences in the response.
""",
},
]
@ -77,7 +77,7 @@ def main():
while True:
# path to your image
image_path = os.path.join(os.getcwd(), "./frames/frame.jpg")
image_path = os.path.join(os.getcwd(), "./screenshots/screenshot.png")
# getting the base64 encoding
base64_image = encode_image(image_path)