Julian Bilcke commited on
Commit ·
40f9c1e
1
Parent(s): 6cf7909
tentative fix for Python 3.12
Browse files76 unmodified lines777879808182306 unmodified lines389390391392393394283 unmodified lines678679680681682683603 unmodified lines128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213336 unmodified lines134013411342134313441345134676 unmodified lines# UI will be in ready-to-start modedef initialize_app_state(self):"""Initialize all app state in one function to ensure correct output count"""# Get dataset info306 unmodified linestraceback.print_exc()raise gr.Error(f"Error copying assets to training dir: {str(e)}")async def start_caption_generation(self, captioning_bot_instructions: str, prompt_prefix: str) -> AsyncGenerator[gr.update, None]:"""Run auto-captioning process"""try:283 unmodified linesexcept Exception as e:return gr.update(value=f"Error saving caption: {str(e)}")def get_model_info(self, model_type: str) -> str:"""Get information about the selected model type"""if model_type == "hunyuan_video":603 unmodified linesoutputs=[])async def on_import_success(enable_splitting, enable_automatic_content_captioning, prompt_prefix):videos = self.list_unprocessed_videos()# If scene detection isn't already running and there are videos to process,# and auto-splitting is enabled, start the detectionif videos and not self.splitter.is_processing() and enable_splitting:await self.start_scene_detection(enable_splitting)msg = "Starting automatic scene detection..."else:# Just copy files without splitting if auto-split disabledfor video_file in VIDEOS_TO_SPLIT_PATH.glob("*.mp4"):await self.splitter.process_video(video_file, enable_splitting=False)msg = "Copying videos without splitting..."copy_files_to_training_dir(prompt_prefix)# Start auto-captioning if enabledif enable_automatic_content_captioning:await self.start_caption_generation(DEFAULT_CAPTIONING_BOT_INSTRUCTIONS,prompt_prefix)return {tabs: gr.Tabs(selected="split_tab"),video_list: videos,detect_status: msg}async def update_titles_after_import(enable_splitting, enable_automatic_content_captioning, prompt_prefix):"""Handle post-import updates including titles"""import_result = await on_import_success(enable_splitting, enable_automatic_content_captioning, prompt_prefix)titles = self.update_titles()return (*import_result, *titles)files.upload(fn=lambda x: self.importer.process_uploaded_files(x),inputs=[files],outputs=[import_status]).success(fn=update_titles_after_import,inputs=[enable_automatic_video_split, enable_automatic_content_captioning, custom_prompt_prefix],outputs=[tabs, video_list, detect_status,6 unmodified linesinputs=[youtube_url],outputs=[import_status]).success(fn=on_import_success,inputs=[enable_automatic_video_split, enable_automatic_content_captioning, custom_prompt_prefix],outputs=[tabs, video_list, detect_status])76 unmodified lines77787980818283848586878889909192939495306 unmodified lines402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438283 unmodified lines722723724725726727728729730731732733734735736737738603 unmodified lines1342134313441345134613471348134913501351135213536 unmodified lines136013611362136313641365136676 unmodified lines# UI will be in ready-to-start modeasync def _process_caption_generator(self, captioning_bot_instructions, prompt_prefix):"""Process the caption generator's results in the background"""try:async for _ in self.captioner.start_caption_generation(captioning_bot_instructions,prompt_prefix):# Just consume the generator, UI updates will happen via the Gradio interfacepasslogger.info("Background captioning completed")except Exception as e:logger.error(f"Error in background captioning: {str(e)}")def initialize_app_state(self):"""Initialize all app state in one function to ensure correct output count"""# Get dataset info306 unmodified linestraceback.print_exc()raise gr.Error(f"Error copying assets to training dir: {str(e)}")async def on_import_success(self, enable_splitting, enable_automatic_content_captioning, prompt_prefix):"""Handle successful import of files"""videos = self.list_unprocessed_videos()# If scene detection isn't already running and there are videos to process,# and auto-splitting is enabled, start the detectionif videos and not self.splitter.is_processing() and enable_splitting:await self.start_scene_detection(enable_splitting)msg = "Starting automatic scene detection..."else:# Just copy files without splitting if auto-split disabledfor video_file in VIDEOS_TO_SPLIT_PATH.glob("*.mp4"):await self.splitter.process_video(video_file, enable_splitting=False)msg = "Copying videos without splitting..."copy_files_to_training_dir(prompt_prefix)# Start auto-captioning if enabled, and handle async generator properlyif enable_automatic_content_captioning:# Create a background task for captioningasyncio.create_task(self._process_caption_generator(DEFAULT_CAPTIONING_BOT_INSTRUCTIONS,prompt_prefix))return {"tabs": gr.Tabs(selected="split_tab"),"video_list": videos,"detect_status": msg}async def start_caption_generation(self, captioning_bot_instructions: str, prompt_prefix: str) -> AsyncGenerator[gr.update, None]:"""Run auto-captioning process"""try:283 unmodified linesexcept Exception as e:return gr.update(value=f"Error saving caption: {str(e)}")async def update_titles_after_import(self, enable_splitting, enable_automatic_content_captioning, prompt_prefix):"""Handle post-import updates including titles"""import_result = await self.on_import_success(enable_splitting, enable_automatic_content_captioning, prompt_prefix)titles = self.update_titles()return (import_result["tabs"],import_result["video_list"],import_result["detect_status"],*titles)def get_model_info(self, model_type: str) -> str:"""Get information about the selected model type"""if model_type == "hunyuan_video":603 unmodified linesoutputs=[])files.upload(fn=lambda x: self.importer.process_uploaded_files(x),inputs=[files],outputs=[import_status]).success(fn=self.update_titles_after_import,inputs=[enable_automatic_video_split, enable_automatic_content_captioning, custom_prompt_prefix],outputs=[tabs, video_list, detect_status,6 unmodified linesinputs=[youtube_url],outputs=[import_status]).success(fn=self.on_import_success,inputs=[enable_automatic_video_split, enable_automatic_content_captioning, custom_prompt_prefix],outputs=[tabs, video_list, detect_status])
app.py+57-37