You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I downloaded the project on April 19th. When running the video interpretation and generating the web page, an error occurred "Error generating code. Check the Developer Console AND the backend logs for details. Feel free to open a Github issue." I went to the cache temp folder and did not find the expected mp4 file, so I continued to troubleshoot. , found in the code, it was automatically deleted, which explains why there is no mp4 file. Then, I disabled automatic deletion and then added manual deletion code to solve the problem. The following is the code.
backend\video\utils.py
import base64
import io
import mimetypes
import os
import tempfile
import uuid
from typing import Any, Union, List, cast
from moviepy.editor import VideoFileClip # type: ignore
from PIL import Image
import math
@fattank thank you for sharing this. I'll look into incorporating this into the repo.
I do think my code is wrong here since the docs say
"If delete is true (the default) and delete_on_close is true (the default), the file is deleted as soon as it is closed. If delete is true and delete_on_close is false, the file is deleted on context manager exit only, or else when the file-like object is finalized."
Calling .close() before VideoFileClip is probably deleting the clip.
Nice job looking into this!
abi
changed the title
I solved the problem that when running the video generation web page, the error " Error generating code. Check the Developer Console AND the backend logs for details. Feel free to open a Github issue. " was reported,
Fix video tempfile deletion prior to close
Apr 22, 2024
I downloaded the project on April 19th. When running the video interpretation and generating the web page, an error occurred "Error generating code. Check the Developer Console AND the backend logs for details. Feel free to open a Github issue." I went to the cache temp folder and did not find the expected mp4 file, so I continued to troubleshoot. , found in the code, it was automatically deleted, which explains why there is no mp4 file. Then, I disabled automatic deletion and then added manual deletion code to solve the problem. The following is the code.
backend\video\utils.py
import base64
import io
import mimetypes
import os
import tempfile
import uuid
from typing import Any, Union, List, cast
from moviepy.editor import VideoFileClip # type: ignore
from PIL import Image
import math
DEBUG = True
TARGET_NUM_SCREENSHOTS = (20)
async def assemble_claude_prompt_video(video_data_url: str) -> list[Any]:
images = split_video_into_screenshots(video_data_url)
def split_video_into_screenshots(video_data_url: str) -> list[Image.Image]:
video_encoded_data = video_data_url.split(",")[1]
video_bytes = base64.b64decode(video_encoded_data)
mime_type = video_data_url.split(";")[0].split(":")[1]
suffix = mimetypes.guess_extension(mime_type)
temp_file_path = None
def save_images_to_tmp(images: List[Image.Image]):
unique_dir_name = f"screenshots_{uuid.uuid4()}"
tmp_screenshots_dir = os.path.join(tempfile.gettempdir(), unique_dir_name)
os.makedirs(tmp_screenshots_dir, exist_ok=True)
for idx, image in enumerate(images):
image_filename = f"screenshot_{idx}.jpg"
tmp_filepath = os.path.join(tmp_screenshots_dir, image_filename)
image.save(tmp_filepath, format="JPEG")
print(f"Saved to {tmp_screenshots_dir}")
def extract_tag_content(tag: str, text: str) -> str:
tag_start = f"<{tag}>"
tag_end = f"</{tag}>"
start_idx = text.find(tag_start)
end_idx = text.find(tag_end, start_idx)
return text[start_idx + len(tag_start):end_idx] if start_idx != -1 and end_idx != -1 else ""
The text was updated successfully, but these errors were encountered: