Spaces:
Paused
Paused
File size: 2,241 Bytes
8f0cb79 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 | from .img_gen import gen_image, decode_img
import os
import re
import logging
# Configure logging
logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s')
import os
def ensure_dir(directory):
"""
Ensures that the specified directory exists. If it does not exist, it creates the directory.
Args:
directory (str): The path to the directory to ensure.
"""
if not os.path.exists(directory):
os.makedirs(directory)
print(f"Created directory: {directory}")
else:
print(f"Directory already exists: {directory}")
ensure_dir("./chunks")
ensure_dir("./images")
ensure_dir("./extracted_frames")
ensure_dir("./recovered")
def render_frame():
# π Ensure the directories exist
if not os.path.exists("./chunks"):
logging.error("Error: 'chunks' directory does not exist. π«")
return
if not os.path.exists("./images"):
os.makedirs("./images")
logging.info("Created 'images' directory. π")
# List all files in the directory
file_list = os.listdir("./chunks")
logging.info(f"Found {len(file_list)} files in 'chunks' directory. π")
# Define a sorting key function that extracts the numeric part of the filename
def sort_key(filename):
match = re.match(r'(\d+)\.bin', filename)
if match:
return int(match.group(1))
return float('inf') # Ensure non-matching filenames are sorted last
# Sort the file list using the custom key function
file_list.sort(key=sort_key)
logging.info("Sorted file list. π’")
index = 0
for f in file_list:
if f.endswith('.bin'):
try:
# Construct the full path to the .bin file
bin_file_path = os.path.join("./chunks", f)
gen_image(bin_file_path, f"images/{index}.png")
logging.info(f"Processed file {f} to images/{index}.png πΌοΈ")
index += 1
except Exception as e:
logging.error(f"Error processing file {f}: {e} β")
else:
logging.warning(f"Skipping non-bin file: {f} π«")
|