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 lines222324252526272819 unmodified lines48495051515253548 unmodified lines636465666667686968 unmodified lines13813914014114114214314421 unmodified linesclass FileUploadHandler: """Handles processing of uploaded files""" def process_uploaded_files(self, file_paths: List[str], enable_splitting: bool) -> str: 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 lines file_ext = file_path.suffix.lower()
if file_ext == '.zip': return self.process_zip_file(file_path, enable_splitting) 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 lines logger.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: 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 files Args:68 unmodified lines logger.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) 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 lines169170171172172173174175176153 unmodified lines330331332332333334335336337219 unmodified lines557558559558560561562563168 unmodified lines dataset_id: str, file_type: str, enable_splitting: bool, progress_callback: Optional[Callable] = None progress_callback: Optional[Callable] = None, custom_prompt_prefix: str = None ) -> str: """Download all files of a specific type from the dataset 153 unmodified lines self, dataset_id: str, enable_splitting: bool, progress_callback: Optional[Callable] = None progress_callback: Optional[Callable] = None, custom_prompt_prefix: str = None ) -> Tuple[str, str]: """Download a dataset and process its video/image content 219 unmodified lines txt_path = file_path.with_suffix('.txt') if txt_path.exists(): caption = txt_path.read_text() caption = add_prefix_to_caption(caption, DEFAULT_PROMPT_PREFIX) 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 lines282930313132333410 unmodified lines454647484849505134 unmodified lines8687888989909192935 unmodified lines991001011011021031041051061071081081091101111121136 unmodified lines12012112212112327 unmodified lines self.youtube_handler = YouTubeDownloader() self.hub_browser = HubDatasetBrowser(self.hf_api) def process_uploaded_files(self, file_paths: List[str], enable_splitting: bool) -> str: 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 lines print(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) 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 lines self, dataset_id: str, enable_splitting: bool, progress_callback: Optional[Callable] = None progress_callback: Optional[Callable] = None, custom_prompt_prefix: str = None ) -> Tuple[str, str]: """Download a dataset and process its video/image content 5 unmodified lines Returns: Tuple of (loading_msg, status_msg) """ return await self.hub_browser.download_dataset(dataset_id, enable_splitting, progress_callback) 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 progress_callback: Optional[Callable] = None, custom_prompt_prefix: str = None ) -> str: """Download a group of files (videos or WebDatasets) 6 unmodified lines Returns: Status message """ return await self.hub_browser.download_file_group(dataset_id, file_type, enable_splitting, progress_callback) return await self.hub_browser.download_file_group(dataset_id, file_type, enable_splitting, progress_callback, custom_prompt_prefix)578 unmodified lines57958058158258358458584 unmodified lines670671672672673674675676677678679680681673674675676677678679578 unmodified lines precomputation_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 lines else: flow_weighting_scheme = "logit_normal"
# Get the custom prompt prefix from the tabs custom_prompt_prefix = None if 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 it prefix = self.app.tabs['caption_tab'].components['custom_prompt_prefix'].value if prefix: # Clean the prefix - remove trailing comma, space or comma+space custom_prompt_prefix = prefix.rstrip(', ') # Use the custom prompt prefix passed as parameter # Clean the prefix - remove trailing comma, space or comma+space if custom_prompt_prefix: custom_prompt_prefix = custom_prompt_prefix.rstrip(', ')
# Create a proper dataset configuration JSON file dataset_config_file = self.app.output_path / "dataset_config.json"266 unmodified lines26726826927027027127227315 unmodified lines2892902912922922932942952962 unmodified lines29930030130130230330430518 unmodified lines324325326326327328329330331266 unmodified lines "" # status_output )
async def _download_with_progress(self, dataset_id, file_type, enable_splitting, progress_callback): 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 lines dataset_id, file_type, enable_splitting, progress_callback=progress_adapter progress_callback=progress_adapter, custom_prompt_prefix=custom_prompt_prefix ) return result2 unmodified lines logger.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: 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 lines dataset_id, file_type, enable_splitting, progress progress, custom_prompt_prefix )) # When download is complete, update the UI64 unmodified lines656667686869707164 unmodified lines # File upload event with enable_splitting parameter upload_event = self.components["files"].upload( fn=self.app.importing.process_uploaded_files, inputs=[self.components["files"], self.components["enable_automatic_video_split"]], 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 lines90690790890991091191291391491591691791812 unmodified lines931932933927934935936937938905 unmodified lines precomputation_items = int(self.components["precomputation_items"].value) lr_warmup_steps = int(self.components["lr_warmup_steps"].value) # Get custom prompt prefix from caption tab custom_prompt_prefix = None if 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 lines precomputation_items=precomputation_items, lr_warmup_steps=lr_warmup_steps, progress=progress, pretrained_lora_path=pretrained_lora_path 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