Spaces:
Build error
Build error
Julian Bilcke commited on
Commit ·
a529bb7
1
Parent(s): 1b19314
add automatic FPS tracking
Browse filesFiles changed (2)
3 unmodified lines4567891099 unmodified lines1101111121131141153 unmodified linesimport shutilfrom typing import Any, Optional, Dict, List, Union, Tuplefrom config import STORAGE_PATH, TRAINING_PATH, STAGING_PATH, TRAINING_VIDEOS_PATH, MODEL_PATH, OUTPUT_PATH, HF_API_TOKEN, MODEL_TYPESfrom utils import extract_scene_info, make_archive, is_image_file, is_video_filelogger = logging.getLogger(__name__)99 unmodified linesif parent_caption and not caption.endswith(parent_caption):caption = f"{caption}\n{parent_caption}"if prompt_prefix and not caption.startswith(prompt_prefix):caption = f"{prompt_prefix}{caption}"3 unmodified lines4567891099 unmodified lines1101111121131141151161171181191201211221233 unmodified linesimport shutilfrom typing import Any, Optional, Dict, List, Union, Tuplefrom config import STORAGE_PATH, TRAINING_PATH, STAGING_PATH, TRAINING_VIDEOS_PATH, MODEL_PATH, OUTPUT_PATH, HF_API_TOKEN, MODEL_TYPESfrom utils import get_video_fps, extract_scene_info, make_archive, is_image_file, is_video_filelogger = logging.getLogger(__name__)99 unmodified linesif parent_caption and not caption.endswith(parent_caption):caption = f"{caption}\n{parent_caption}"# Add FPS information for videosif is_video_file(file_path) and caption:# Only add FPS if not already presentif not any(f"FPS, " in line for line in caption.split('\n')):fps_info = get_video_fps(file_path)if fps_info:caption = f"{fps_info}{caption}"if prompt_prefix and not caption.startswith(prompt_prefix):caption = f"{prompt_prefix}{caption}"
12345678910116 unmodified lines181920212223import osimport shutilfrom huggingface_hub import HfApi, create_repofrom pathlib import Pathimport jsonimport refrom typing import Any, Optional, Dict, List, Union, Tupledef make_archive(source: str | Path, destination: str | Path):source = str(source)destination = str(destination)6 unmodified linesshutil.make_archive(name, format, archive_from, archive_to)shutil.move('%s.%s'%(name,format), destination)def extract_scene_info(filename: str) -> Tuple[str, Optional[int]]:"""Extract base name and scene number from filename1234567891011121314156 unmodified lines2223242526272829303132333435363738394041424344454647484950515253545556575859606162636465import osimport shutilimport subprocessfrom huggingface_hub import HfApi, create_repofrom pathlib import Pathimport jsonimport reimport loggingfrom typing import Any, Optional, Dict, List, Union, Tuplelogger = logging.getLogger(__name__)def make_archive(source: str | Path, destination: str | Path):source = str(source)destination = str(destination)6 unmodified linesshutil.make_archive(name, format, archive_from, archive_to)shutil.move('%s.%s'%(name,format), destination)def get_video_fps(video_path: Path) -> Optional[str]:"""Get FPS information from video file using ffprobeArgs:video_path: Path to video fileReturns:FPS string (e.g. "24 FPS, ") or None if unable to determine"""try:cmd = ['ffprobe','-v', 'error','-select_streams', 'v:0','-show_entries', 'stream=avg_frame_rate','-of', 'default=noprint_wrappers=1:nokey=1',str(video_path)]result = subprocess.run(cmd, capture_output=True, text=True)if result.returncode != 0:logger.warning(f"Error getting FPS for {video_path}: {result.stderr}")return Nonefps = result.stdout.strip()if '/' in fps:# Convert fraction to decimalnum, den = map(int, fps.split('/'))if den == 0:return Nonefps = str(round(num / den))return f"{fps} FPS, "except Exception as e:logger.warning(f"Failed to get FPS for {video_path}: {e}")return Nonedef extract_scene_info(filename: str) -> Tuple[str, Optional[int]]:"""Extract base name and scene number from filename
finetrainers_utils.py+9-1
utils.py+42