Spaces:
Running
Running
File size: 1,084 Bytes
f0c79f8 |
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 |
import os
import logging
from typing import Dict, Any
# Set up logging
logging.basicConfig(level=logging.INFO)
logger = logging.getLogger(__name__)
def ensure_directories():
"""
Ensure required directories exist.
"""
dirs = ["outputs", "temp"]
for dir_path in dirs:
os.makedirs(dir_path, exist_ok=True)
logger.info(f"Ensured directory exists: {dir_path}")
def cleanup_temp_files():
"""
Clean up temporary files that are no longer needed.
"""
try:
import glob
import time
# Delete files in temp directory that are older than 1 hour
current_time = time.time()
one_hour_ago = current_time - 3600
for file_path in glob.glob("temp/*"):
if os.path.isfile(file_path):
file_stats = os.stat(file_path)
if file_stats.st_mtime < one_hour_ago:
os.remove(file_path)
logger.info(f"Deleted old temp file: {file_path}")
except Exception as e:
logger.error(f"Error cleaning up temp files: {str(e)}") |