You can now load the package via spacy.load('en_core_web_sm')
Received subreddit threads Successfully.
Thread ID is 9whgf4
╭───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮│ Saving Text to MP3 files... │╰───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯Working... ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 2.2 it/s
Saved Text to MP3 files successfully.
╭───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮│ Downloading screenshots of reddit posts... │╰───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯Generating story mode images...
Rendering Image ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
╭───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮│ Sorry, something went wrong with this version! Try again, and feel free to report this issue at GitHub or the Discord ││ community. ││ Version: 3.3.0 ││ Error: [Errno 2] No such file or directory: ││ 'C:\Users\buggy\Desktop\RedditVideoMakerBot-3.3.0\assets\temp\9whgf4\png\img0.png' ││ Config: {'allow_nsfw': False, 'theme': 'dark', 'times_to_run': 1, 'opacity': 0.9, 'storymode': True, 'storymodemethod': 1, ││ 'storymode_max_length': 1000, 'resolution_w': 1080, 'resolution_h': 1920, 'zoom': 1.0, 'channel_name': 'Reddit Tales', ││ 'background': {'background_video': 'minecraft', 'background_audio': 'lofi', 'background_audio_volume': 0.15, ││ 'enable_extra_audio': False, 'background_thumbnail': False, 'background_thumbnail_font_family': 'arial', ││ 'background_thumbnail_font_size': 96, 'background_thumbnail_font_color': '255,255,255'}, 'tts': {'voice_choice': 'pyttsx', ││ 'random_voice': True, 'elevenlabs_voice_name': 'Bella', 'elevenlabs_api_key': 'REDACTED', 'aws_polly_voice': 'Matthew', ││ 'streamlabs_polly_voice': 'o', 'tiktok_voice': 'en_us_001', 'tiktok_sessionid': 'REDACTED', 'python_voice': '1', ││ 'py_voice_num': '2', 'silence_duration': 0.3, 'no_emojis': False}} │╰───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯Traceback (most recent call last):
File "C:\Users\buggy\Desktop\RedditVideoMakerBot-3.3.0\main.py", line 135, in
raise err
File "C:\Users\buggy\Desktop\RedditVideoMakerBot-3.3.0\main.py", line 117, in
run_many(config["settings"]["times_to_run"])
File "C:\Users\buggy\Desktop\RedditVideoMakerBot-3.3.0\main.py", line 72, in run_many
main()
File "C:\Users\buggy\Desktop\RedditVideoMakerBot-3.3.0\main.py", line 56, in main
get_screenshots_of_reddit_posts(reddit_object, number_of_comments)
File "C:\Users\buggy\Desktop\RedditVideoMakerBot-3.3.0\video_creation\screenshot_downloader.py", line 46, in get_screenshots_of_reddit_posts
return imagemaker(
File "C:\Users\buggy\Desktop\RedditVideoMakerBot-3.3.0\utils\imagenarator.py", line 75, in imagemaker
image.save(f"assets/temp/{id}/png/img{idx}.png")
File "C:\Users\buggy\Desktop\RedditVideoMakerBot-3.3.0\myenv\lib\site-packages\PIL\Image.py", line 2456, in save
fp = builtins.open(filename, "w+b")
FileNotFoundError: [Errno 2] No such file or directory: 'C:\Users\buggy\Desktop\RedditVideoMakerBot-3.3.0\assets\temp\9whgf4\png\img0.png'
Assistant
It looks like the script encountered a FileNotFoundError because it couldn't find the directory where it's trying to save images. Here are a few steps you can take to resolve this issue:
Check Directory Path: Make sure that the directory structure exists up to the point where the script is trying to save the images. Specifically, ensure that C:\\Users\\buggy\\Desktop\\RedditVideoMakerBot-3.3.0\\assets\\temp\\9whgf4\\png\\ is created before the script runs this operation.
Permissions: Verify that you have the necessary permissions to write to the directory. You should be able to create folders and files in the specified path.
Modify the Script: Consider adding a line in the script to automatically create the directory if it doesn't exist. You can use with the parameter to prevent errors when the directory already exists:
User
how do i do that?
Assistant
To address the issue with directory creation in your script, you can modify it to automatically create the necessary directories before attempting to save the images. Here’s a step-by-step guide on how to do it:
Locate the Problematic Code:
Find the line of code where the script tries to save the image. Based on the error message, it's in the imagemaker function:
image.save(f"assets/temp/{id}/png/img{idx}.png")
Import Required Module:
At the top of the script file where you're handling image saving, import the os module if it's not already imported:
User
this is what i have: import os
import re
import textwrap
from PIL import Image, ImageDraw, ImageFont
from rich.progress import track
from TTS.engine_wrapper import process_text
from utils.fonts import getheight, getsize
Assistant
To ensure that the directories are present before saving images, you can add a directory creation step inside your imagemaker function. Here's how you can modify your script:
Import os Module: You've already imported the os module, so no changes are needed here.
os.makedirs()
exist_ok=True
import os
directory = 'C:\\Users\\buggy\\Desktop\\RedditVideoMakerBot-3.3.0\\assets\\temp\\9whgf4\\png\\'
os.makedirs(directory, exist_ok=True)
Check config settings: Ensure that the path and ID are being set correctly in your configuration, and the id is appropriately assigned before the image save operation.
Run with Debugging: Add some print statements or use a debugger to track the current working directory and to verify that the paths are being constructed correctly.
If the issue persists after these steps, you may consider reinstalling dependencies or reaching out to the community for the specific project on platforms like GitHub, as the error message suggests.
import os
Create Directories if Needed:
Before saving the image, use the os.makedirs() function to create the necessary directories. Add this code snippet right before the image.save() call:
Here's how it might look in the context of your function:
def imagemaker(images, id):
for idx, image in enumerate(images):
# Ensure the directory exists
directory = f'assets/temp/{id}/png/'
os.makedirs(directory, exist_ok=True)
# Save the image
image.save(f"{directory}/img{idx}.png")
Run Your Script:
Save the changes to your script and try running it again. This time, the script should automatically create all necessary directories before saving the images.
By using os.makedirs() with exist_ok=True, you ensure that the directory is created if it does not exist, and no error is raised if it already exists. This should help prevent the FileNotFoundError you encountered.
def draw_multiple_line_text(
image, text, font, text_color, padding, wrap=50, transparent=False
) -> None:
"""
Draw multiline text over given image
"""
draw = ImageDraw.Draw(image)
font_height = getheight(font, text)
image_width, image_height = image.size
lines = textwrap.wrap(text, width=wrap)
y = (image_height / 2) - (((font_height + (len(lines) * padding) / len(lines)) * len(lines)) / 2)
for line in lines:
line_width, line_height = getsize(font, line)
if transparent:
shadowcolor = "black"
for i in range(1, 5):
draw.text(
((image_width - line_width) / 2 - i, y - i),
line,
font=font,
fill=shadowcolor,
)
draw.text(
((image_width - line_width) / 2 + i, y - i),
line,
font=font,
fill=shadowcolor,
)
draw.text(
((image_width - line_width) / 2 - i, y + i),
line,
font=font,
fill=shadowcolor,
)
draw.text(
((image_width - line_width) / 2 + i, y + i),
line,
font=font,
fill=shadowcolor,
)
draw.text(((image_width - line_width) / 2, y), line, font=font, fill=text_color)
y += line_height + padding
def imagemaker(theme, reddit_obj: dict, txtclr, padding=5, transparent=False) -> None:
"""
Render Images for video
"""
texts = reddit_obj["thread_post"]
id = re.sub(r"[^\w\s-]", "", reddit_obj["thread_id"])
if transparent:
font = ImageFont.truetype(os.path.join("fonts", "Roboto-Bold.ttf"), 100)
else:
font = ImageFont.truetype(os.path.join("fonts", "Roboto-Regular.ttf"), 100)
size = (1920, 1080)
image = Image.new("RGBA", size, theme)
for idx, text in track(enumerate(texts), "Rendering Image"):
image = Image.new("RGBA", size, theme)
text = process_text(text, False)
draw_multiple_line_text(image, text, font, txtclr, padding, wrap=30, transparent=transparent)
image.save(f"assets/temp/{id}/png/img{idx}.png")
Determine the Directory Path: Before the loop, determine the full directory path where the images will be saved.
Create Directory Using os.makedirs(): Use os.makedirs() to ensure the directory structure exists. Here's the updated imagemaker function:
def imagemaker(theme, reddit_obj: dict, txtclr, padding=5, transparent=False) -> None:
"""
Render Images for video
"""
texts = reddit_obj["thread_post"]
id = re.sub(r"[^\w\s-]", "", reddit_obj["thread_id"])
# Determine the directory path for images
directory = f"assets/temp/{id}/png/"
# Create the directory if it doesn't exist
os.makedirs(directory, exist_ok=True)
if transparent:
font = ImageFont.truetype(os.path.join("fonts", "Roboto-Bold.ttf"), 100)
else:
font = ImageFont.truetype(os.path.join("fonts", "Roboto-Regular.ttf"), 100)
size = (1920, 1080)
image = Image.new("RGBA", size, theme)
for idx, text in track(enumerate(texts), "Rendering Image"):
image = Image.new("RGBA", size, theme)
text = process_text(text, False)
draw_multiple_line_text(image, text, font, txtclr, padding, wrap=30, transparent=transparent)
# Save the image to the specified directory
image.save(f"{directory}/img{idx}.png")
What This Does:
Directory Creation: os.makedirs(directory, exist_ok=True) ensures that the directory is created if it doesn't exist already. The exist_ok=True parameter prevents any errors if the directory already exists.
Saving Images: The path where the image is saved now uses the directory variable, ensuring consistency and clarity in the paths used.
This modification will ensure any required directories are created before attempting to save images, thereby preventing the FileNotFoundError you encountered.