Julian Bilcke commited on
Commit ·
fc0385d
1
Parent(s): ece1c33
fix for the custom prompt prefix
Browse filesFiles changed (7)
- vms/ui/project/services/importing/file_upload.py+4-4
- vms/ui/project/services/importing/hub_dataset.py+5-3
- vms/ui/project/services/importing/import_service.py+8-6
- vms/ui/project/services/training.py+5-10
- vms/ui/project/tabs/import_tab/hub_tab.py+6-4
- vms/ui/project/tabs/import_tab/upload_tab.py+1-1
- vms/ui/project/tabs/train_tab.py+9-1
21 unmodified lines2223242526272819 unmodified lines484950515253548 unmodified lines6364656667686968 unmodified lines13813914014114214314421 unmodified linesclass FileUploadHandler:"""Handles processing of uploaded files"""def process_uploaded_files(self, file_paths: List[str], enable_splitting: bool) -> str:"""Process uploaded file (ZIP, TAR, MP4, or image)Args:19 unmodified linesfile_ext = file_path.suffix.lower()if file_ext == '.zip':return self.process_zip_file(file_path, enable_splitting)elif file_ext == '.tar':return self.process_tar_file(file_path, enable_splitting)elif file_ext == '.mp4' or file_ext == '.webm':8 unmodified lineslogger.error(f"Error processing file {file_path}: {str(e)}", exc_info=True)raise gr.Error(f"Error processing file: {str(e)}")def process_zip_file(self, file_path: Path, enable_splitting: bool) -> str:"""Process uploaded ZIP file containing media files or WebDataset tar filesArgs:68 unmodified lineslogger.info(f"Copied caption file for {file}")elif is_image_file(file_path):caption = txt_path.read_text()caption = add_prefix_to_caption(caption, DEFAULT_PROMPT_PREFIX)target_path.with_suffix('.txt').write_text(caption)logger.info(f"Processed caption for {file}")21 unmodified lines2223242526272819 unmodified lines484950515253548 unmodified lines6364656667686968 unmodified lines13813914014114214314421 unmodified linesclass FileUploadHandler:"""Handles processing of uploaded files"""def process_uploaded_files(self, file_paths: List[str], enable_splitting: bool, custom_prompt_prefix: str = None) -> str:"""Process uploaded file (ZIP, TAR, MP4, or image)Args:19 unmodified linesfile_ext = file_path.suffix.lower()if file_ext == '.zip':return self.process_zip_file(file_path, enable_splitting, custom_prompt_prefix)elif file_ext == '.tar':return self.process_tar_file(file_path, enable_splitting)elif file_ext == '.mp4' or file_ext == '.webm':8 unmodified lineslogger.error(f"Error processing file {file_path}: {str(e)}", exc_info=True)raise gr.Error(f"Error processing file: {str(e)}")def process_zip_file(self, file_path: Path, enable_splitting: bool, custom_prompt_prefix: str = None) -> str:"""Process uploaded ZIP file containing media files or WebDataset tar filesArgs:68 unmodified lineslogger.info(f"Copied caption file for {file}")elif is_image_file(file_path):caption = txt_path.read_text()caption = add_prefix_to_caption(caption, custom_prompt_prefix or DEFAULT_PROMPT_PREFIX)target_path.with_suffix('.txt').write_text(caption)logger.info(f"Processed caption for {file}")
168 unmodified lines169170171172173174175153 unmodified lines329330331332333334335219 unmodified lines555556557558559560561168 unmodified linesdataset_id: str,file_type: str,enable_splitting: bool,progress_callback: Optional[Callable] = None) -> str:"""Download all files of a specific type from the dataset153 unmodified linesself,dataset_id: str,enable_splitting: bool,progress_callback: Optional[Callable] = None) -> Tuple[str, str]:"""Download a dataset and process its video/image content219 unmodified linestxt_path = file_path.with_suffix('.txt')if txt_path.exists():caption = txt_path.read_text()caption = add_prefix_to_caption(caption, DEFAULT_PROMPT_PREFIX)target_path.with_suffix('.txt').write_text(caption)logger.info(f"Processed caption for {file_path.name}")168 unmodified lines169170171172173174175176153 unmodified lines330331332333334335336337219 unmodified lines557558559560561562563168 unmodified linesdataset_id: str,file_type: str,enable_splitting: bool,progress_callback: Optional[Callable] = None,custom_prompt_prefix: str = None) -> str:"""Download all files of a specific type from the dataset153 unmodified linesself,dataset_id: str,enable_splitting: bool,progress_callback: Optional[Callable] = None,custom_prompt_prefix: str = None) -> Tuple[str, str]:"""Download a dataset and process its video/image content219 unmodified linestxt_path = file_path.with_suffix('.txt')if txt_path.exists():caption = txt_path.read_text()caption = add_prefix_to_caption(caption, custom_prompt_prefix or DEFAULT_PROMPT_PREFIX)target_path.with_suffix('.txt').write_text(caption)logger.info(f"Processed caption for {file_path.name}")
27 unmodified lines2829303132333410 unmodified lines4546474849505134 unmodified lines868788899091925 unmodified lines98991001011021031041051061071081091101116 unmodified lines11811912012127 unmodified linesself.youtube_handler = YouTubeDownloader()self.hub_browser = HubDatasetBrowser(self.hf_api)def process_uploaded_files(self, file_paths: List[str], enable_splitting: bool) -> str:"""Process uploaded file (ZIP, TAR, MP4, or image)Args:10 unmodified linesprint(f"process_uploaded_files(..., enable_splitting = {enable_splitting:})")print(f"process_uploaded_files: calling self.file_handler.process_uploaded_files")return self.file_handler.process_uploaded_files(file_paths, enable_splitting)def download_youtube_video(self, url: str, enable_splitting: bool, progress=None) -> str:"""Download a video from YouTube34 unmodified linesself,dataset_id: str,enable_splitting: bool,progress_callback: Optional[Callable] = None) -> Tuple[str, str]:"""Download a dataset and process its video/image content5 unmodified linesReturns:Tuple of (loading_msg, status_msg)"""return await self.hub_browser.download_dataset(dataset_id, enable_splitting, progress_callback)async def download_file_group(self,dataset_id: str,file_type: str,enable_splitting: bool,progress_callback: Optional[Callable] = None) -> str:"""Download a group of files (videos or WebDatasets)6 unmodified linesReturns:Status message"""return await self.hub_browser.download_file_group(dataset_id, file_type, enable_splitting, progress_callback)27 unmodified lines2829303132333410 unmodified lines4546474849505134 unmodified lines86878889909192935 unmodified lines991001011021031041051061071081091101111121136 unmodified lines12012112212327 unmodified linesself.youtube_handler = YouTubeDownloader()self.hub_browser = HubDatasetBrowser(self.hf_api)def process_uploaded_files(self, file_paths: List[str], enable_splitting: bool, custom_prompt_prefix: str = None) -> str:"""Process uploaded file (ZIP, TAR, MP4, or image)Args:10 unmodified linesprint(f"process_uploaded_files(..., enable_splitting = {enable_splitting:})")print(f"process_uploaded_files: calling self.file_handler.process_uploaded_files")return self.file_handler.process_uploaded_files(file_paths, enable_splitting, custom_prompt_prefix)def download_youtube_video(self, url: str, enable_splitting: bool, progress=None) -> str:"""Download a video from YouTube34 unmodified linesself,dataset_id: str,enable_splitting: bool,progress_callback: Optional[Callable] = None,custom_prompt_prefix: str = None) -> Tuple[str, str]:"""Download a dataset and process its video/image content5 unmodified linesReturns:Tuple of (loading_msg, status_msg)"""return await self.hub_browser.download_dataset(dataset_id, enable_splitting, progress_callback, custom_prompt_prefix)async def download_file_group(self,dataset_id: str,file_type: str,enable_splitting: bool,progress_callback: Optional[Callable] = None,custom_prompt_prefix: str = None) -> str:"""Download a group of files (videos or WebDatasets)6 unmodified linesReturns:Status message"""return await self.hub_browser.download_file_group(dataset_id, file_type, enable_splitting, progress_callback, custom_prompt_prefix)
578 unmodified lines57958058158258358484 unmodified lines669670671672673674675676677678679680681682683684578 unmodified linesprecomputation_items: int = DEFAULT_PRECOMPUTATION_ITEMS,lr_warmup_steps: int = DEFAULT_NB_LR_WARMUP_STEPS,progress: Optional[gr.Progress] = None,) -> Tuple[str, str]:"""Start training with finetrainers"""84 unmodified lineselse:flow_weighting_scheme = "logit_normal"# Get the custom prompt prefix from the tabscustom_prompt_prefix = Noneif hasattr(self, 'app') and self.app is not None:if hasattr(self.app, 'tabs') and 'caption_tab' in self.app.tabs:if hasattr(self.app.tabs['caption_tab'], 'components') and 'custom_prompt_prefix' in self.app.tabs['caption_tab'].components:# Get the value and clean itprefix = self.app.tabs['caption_tab'].components['custom_prompt_prefix'].valueif prefix:# Clean the prefix - remove trailing comma, space or comma+spacecustom_prompt_prefix = prefix.rstrip(', ')# Create a proper dataset configuration JSON filedataset_config_file = self.app.output_path / "dataset_config.json"578 unmodified lines57958058158258358458584 unmodified lines670671672673674675676677678679578 unmodified linesprecomputation_items: int = DEFAULT_PRECOMPUTATION_ITEMS,lr_warmup_steps: int = DEFAULT_NB_LR_WARMUP_STEPS,progress: Optional[gr.Progress] = None,custom_prompt_prefix: Optional[str] = None,) -> Tuple[str, str]:"""Start training with finetrainers"""84 unmodified lineselse:flow_weighting_scheme = "logit_normal"# Use the custom prompt prefix passed as parameter# Clean the prefix - remove trailing comma, space or comma+spaceif custom_prompt_prefix:custom_prompt_prefix = custom_prompt_prefix.rstrip(', ')# Create a proper dataset configuration JSON filedataset_config_file = self.app.output_path / "dataset_config.json"
266 unmodified lines26726826927027127227315 unmodified lines2892902912922932942952 unmodified lines29829930030130230330418 unmodified lines323324325326327328329266 unmodified lines"" # status_output)async def _download_with_progress(self, dataset_id, file_type, enable_splitting, progress_callback):"""Wrapper for download_file_group that integrates with progress tracking"""try:# Set up the progress callback adapter15 unmodified linesdataset_id,file_type,enable_splitting,progress_callback=progress_adapter)return result2 unmodified lineslogger.error(f"Error in download with progress: {str(e)}", exc_info=True)return f"Error: {str(e)}"def download_file_group(self, dataset_id: str, enable_splitting: bool, file_type: str, progress=gr.Progress()) -> Tuple:"""Handle download of a group of files (videos or WebDatasets) with progress tracking"""try:if not dataset_id:18 unmodified linesdataset_id,file_type,enable_splitting,progress))# When download is complete, update the UI266 unmodified lines26726826927027127227315 unmodified lines2892902912922932942952962 unmodified lines29930030130230330430518 unmodified lines324325326327328329330331266 unmodified lines"" # status_output)async def _download_with_progress(self, dataset_id, file_type, enable_splitting, progress_callback, custom_prompt_prefix=None):"""Wrapper for download_file_group that integrates with progress tracking"""try:# Set up the progress callback adapter15 unmodified linesdataset_id,file_type,enable_splitting,progress_callback=progress_adapter,custom_prompt_prefix=custom_prompt_prefix)return result2 unmodified lineslogger.error(f"Error in download with progress: {str(e)}", exc_info=True)return f"Error: {str(e)}"def download_file_group(self, dataset_id: str, enable_splitting: bool, file_type: str, custom_prompt_prefix: str = None, progress=gr.Progress()) -> Tuple:"""Handle download of a group of files (videos or WebDatasets) with progress tracking"""try:if not dataset_id:18 unmodified linesdataset_id,file_type,enable_splitting,progress,custom_prompt_prefix))# When download is complete, update the UI
64 unmodified lines6566676869707164 unmodified lines# File upload event with enable_splitting parameterupload_event = self.components["files"].upload(fn=self.app.importing.process_uploaded_files,inputs=[self.components["files"], self.components["enable_automatic_video_split"]],outputs=[self.components["import_status"]]).success(fn=self.app.tabs["import_tab"].on_import_success,64 unmodified lines6566676869707164 unmodified lines# File upload event with enable_splitting parameterupload_event = self.components["files"].upload(fn=self.app.importing.process_uploaded_files,inputs=[self.components["files"], self.components["enable_automatic_video_split"], self.app.tabs["caption_tab"].components["custom_prompt_prefix"]],outputs=[self.components["import_status"]]).success(fn=self.app.tabs["import_tab"].on_import_success,
905 unmodified lines90690790890991091112 unmodified lines924925926927928929930905 unmodified linesprecomputation_items = int(self.components["precomputation_items"].value)lr_warmup_steps = int(self.components["lr_warmup_steps"].value)# Start training (it will automatically use the checkpoint if provided)try:return self.app.training.start_training(12 unmodified linesprecomputation_items=precomputation_items,lr_warmup_steps=lr_warmup_steps,progress=progress,pretrained_lora_path=pretrained_lora_path)except Exception as e:logger.exception("Error starting training")905 unmodified lines90690790890991091191291391491591691791812 unmodified lines931932933934935936937938905 unmodified linesprecomputation_items = int(self.components["precomputation_items"].value)lr_warmup_steps = int(self.components["lr_warmup_steps"].value)# Get custom prompt prefix from caption tabcustom_prompt_prefix = Noneif hasattr(self.app, 'tabs') and 'caption_tab' in self.app.tabs:caption_tab = self.app.tabs['caption_tab']if hasattr(caption_tab, 'components') and 'custom_prompt_prefix' in caption_tab.components:custom_prompt_prefix = caption_tab.components['custom_prompt_prefix'].value# Start training (it will automatically use the checkpoint if provided)try:return self.app.training.start_training(12 unmodified linesprecomputation_items=precomputation_items,lr_warmup_steps=lr_warmup_steps,progress=progress,pretrained_lora_path=pretrained_lora_path,custom_prompt_prefix=custom_prompt_prefix)except Exception as e:logger.exception("Error starting training")
vms/ui/project/services/importing/file_upload.py+4-4
vms/ui/project/services/importing/hub_dataset.py+5-3
vms/ui/project/services/importing/import_service.py+8-6
vms/ui/project/services/training.py+5-10
vms/ui/project/tabs/import_tab/hub_tab.py+6-4
vms/ui/project/tabs/import_tab/upload_tab.py+1-1
vms/ui/project/tabs/train_tab.py+9-1