Spaces:
Runtime error
Runtime error
Julian Bilcke
commited on
Commit
·
40f9c1e
1
Parent(s):
6cf7909
tentative fix for Python 3.12
Browse files
app.py
CHANGED
|
@@ -77,6 +77,19 @@ class VideoTrainerUI:
|
|
| 77 |
# UI will be in ready-to-start mode
|
| 78 |
|
| 79 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 80 |
def initialize_app_state(self):
|
| 81 |
"""Initialize all app state in one function to ensure correct output count"""
|
| 82 |
# Get dataset info
|
|
@@ -389,6 +402,37 @@ class VideoTrainerUI:
|
|
| 389 |
traceback.print_exc()
|
| 390 |
raise gr.Error(f"Error copying assets to training dir: {str(e)}")
|
| 391 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 392 |
async def start_caption_generation(self, captioning_bot_instructions: str, prompt_prefix: str) -> AsyncGenerator[gr.update, None]:
|
| 393 |
"""Run auto-captioning process"""
|
| 394 |
try:
|
|
@@ -678,6 +722,17 @@ class VideoTrainerUI:
|
|
| 678 |
except Exception as e:
|
| 679 |
return gr.update(value=f"Error saving caption: {str(e)}")
|
| 680 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 681 |
def get_model_info(self, model_type: str) -> str:
|
| 682 |
"""Get information about the selected model type"""
|
| 683 |
if model_type == "hunyuan_video":
|
|
@@ -1287,47 +1342,12 @@ class VideoTrainerUI:
|
|
| 1287 |
outputs=[]
|
| 1288 |
)
|
| 1289 |
|
| 1290 |
-
async def on_import_success(enable_splitting, enable_automatic_content_captioning, prompt_prefix):
|
| 1291 |
-
videos = self.list_unprocessed_videos()
|
| 1292 |
-
# If scene detection isn't already running and there are videos to process,
|
| 1293 |
-
# and auto-splitting is enabled, start the detection
|
| 1294 |
-
if videos and not self.splitter.is_processing() and enable_splitting:
|
| 1295 |
-
await self.start_scene_detection(enable_splitting)
|
| 1296 |
-
msg = "Starting automatic scene detection..."
|
| 1297 |
-
else:
|
| 1298 |
-
# Just copy files without splitting if auto-split disabled
|
| 1299 |
-
for video_file in VIDEOS_TO_SPLIT_PATH.glob("*.mp4"):
|
| 1300 |
-
await self.splitter.process_video(video_file, enable_splitting=False)
|
| 1301 |
-
msg = "Copying videos without splitting..."
|
| 1302 |
-
|
| 1303 |
-
copy_files_to_training_dir(prompt_prefix)
|
| 1304 |
-
|
| 1305 |
-
# Start auto-captioning if enabled
|
| 1306 |
-
if enable_automatic_content_captioning:
|
| 1307 |
-
await self.start_caption_generation(
|
| 1308 |
-
DEFAULT_CAPTIONING_BOT_INSTRUCTIONS,
|
| 1309 |
-
prompt_prefix
|
| 1310 |
-
)
|
| 1311 |
-
|
| 1312 |
-
return {
|
| 1313 |
-
tabs: gr.Tabs(selected="split_tab"),
|
| 1314 |
-
video_list: videos,
|
| 1315 |
-
detect_status: msg
|
| 1316 |
-
}
|
| 1317 |
-
|
| 1318 |
-
|
| 1319 |
-
async def update_titles_after_import(enable_splitting, enable_automatic_content_captioning, prompt_prefix):
|
| 1320 |
-
"""Handle post-import updates including titles"""
|
| 1321 |
-
import_result = await on_import_success(enable_splitting, enable_automatic_content_captioning, prompt_prefix)
|
| 1322 |
-
titles = self.update_titles()
|
| 1323 |
-
return (*import_result, *titles)
|
| 1324 |
-
|
| 1325 |
files.upload(
|
| 1326 |
fn=lambda x: self.importer.process_uploaded_files(x),
|
| 1327 |
inputs=[files],
|
| 1328 |
outputs=[import_status]
|
| 1329 |
).success(
|
| 1330 |
-
fn=update_titles_after_import,
|
| 1331 |
inputs=[enable_automatic_video_split, enable_automatic_content_captioning, custom_prompt_prefix],
|
| 1332 |
outputs=[
|
| 1333 |
tabs, video_list, detect_status,
|
|
@@ -1340,7 +1360,7 @@ class VideoTrainerUI:
|
|
| 1340 |
inputs=[youtube_url],
|
| 1341 |
outputs=[import_status]
|
| 1342 |
).success(
|
| 1343 |
-
fn=on_import_success,
|
| 1344 |
inputs=[enable_automatic_video_split, enable_automatic_content_captioning, custom_prompt_prefix],
|
| 1345 |
outputs=[tabs, video_list, detect_status]
|
| 1346 |
)
|
|
|
|
| 77 |
# UI will be in ready-to-start mode
|
| 78 |
|
| 79 |
|
| 80 |
+
async def _process_caption_generator(self, captioning_bot_instructions, prompt_prefix):
|
| 81 |
+
"""Process the caption generator's results in the background"""
|
| 82 |
+
try:
|
| 83 |
+
async for _ in self.captioner.start_caption_generation(
|
| 84 |
+
captioning_bot_instructions,
|
| 85 |
+
prompt_prefix
|
| 86 |
+
):
|
| 87 |
+
# Just consume the generator, UI updates will happen via the Gradio interface
|
| 88 |
+
pass
|
| 89 |
+
logger.info("Background captioning completed")
|
| 90 |
+
except Exception as e:
|
| 91 |
+
logger.error(f"Error in background captioning: {str(e)}")
|
| 92 |
+
|
| 93 |
def initialize_app_state(self):
|
| 94 |
"""Initialize all app state in one function to ensure correct output count"""
|
| 95 |
# Get dataset info
|
|
|
|
| 402 |
traceback.print_exc()
|
| 403 |
raise gr.Error(f"Error copying assets to training dir: {str(e)}")
|
| 404 |
|
| 405 |
+
async def on_import_success(self, enable_splitting, enable_automatic_content_captioning, prompt_prefix):
|
| 406 |
+
"""Handle successful import of files"""
|
| 407 |
+
videos = self.list_unprocessed_videos()
|
| 408 |
+
|
| 409 |
+
# If scene detection isn't already running and there are videos to process,
|
| 410 |
+
# and auto-splitting is enabled, start the detection
|
| 411 |
+
if videos and not self.splitter.is_processing() and enable_splitting:
|
| 412 |
+
await self.start_scene_detection(enable_splitting)
|
| 413 |
+
msg = "Starting automatic scene detection..."
|
| 414 |
+
else:
|
| 415 |
+
# Just copy files without splitting if auto-split disabled
|
| 416 |
+
for video_file in VIDEOS_TO_SPLIT_PATH.glob("*.mp4"):
|
| 417 |
+
await self.splitter.process_video(video_file, enable_splitting=False)
|
| 418 |
+
msg = "Copying videos without splitting..."
|
| 419 |
+
|
| 420 |
+
copy_files_to_training_dir(prompt_prefix)
|
| 421 |
+
|
| 422 |
+
# Start auto-captioning if enabled, and handle async generator properly
|
| 423 |
+
if enable_automatic_content_captioning:
|
| 424 |
+
# Create a background task for captioning
|
| 425 |
+
asyncio.create_task(self._process_caption_generator(
|
| 426 |
+
DEFAULT_CAPTIONING_BOT_INSTRUCTIONS,
|
| 427 |
+
prompt_prefix
|
| 428 |
+
))
|
| 429 |
+
|
| 430 |
+
return {
|
| 431 |
+
"tabs": gr.Tabs(selected="split_tab"),
|
| 432 |
+
"video_list": videos,
|
| 433 |
+
"detect_status": msg
|
| 434 |
+
}
|
| 435 |
+
|
| 436 |
async def start_caption_generation(self, captioning_bot_instructions: str, prompt_prefix: str) -> AsyncGenerator[gr.update, None]:
|
| 437 |
"""Run auto-captioning process"""
|
| 438 |
try:
|
|
|
|
| 722 |
except Exception as e:
|
| 723 |
return gr.update(value=f"Error saving caption: {str(e)}")
|
| 724 |
|
| 725 |
+
async def update_titles_after_import(self, enable_splitting, enable_automatic_content_captioning, prompt_prefix):
|
| 726 |
+
"""Handle post-import updates including titles"""
|
| 727 |
+
import_result = await self.on_import_success(enable_splitting, enable_automatic_content_captioning, prompt_prefix)
|
| 728 |
+
titles = self.update_titles()
|
| 729 |
+
return (
|
| 730 |
+
import_result["tabs"],
|
| 731 |
+
import_result["video_list"],
|
| 732 |
+
import_result["detect_status"],
|
| 733 |
+
*titles
|
| 734 |
+
)
|
| 735 |
+
|
| 736 |
def get_model_info(self, model_type: str) -> str:
|
| 737 |
"""Get information about the selected model type"""
|
| 738 |
if model_type == "hunyuan_video":
|
|
|
|
| 1342 |
outputs=[]
|
| 1343 |
)
|
| 1344 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1345 |
files.upload(
|
| 1346 |
fn=lambda x: self.importer.process_uploaded_files(x),
|
| 1347 |
inputs=[files],
|
| 1348 |
outputs=[import_status]
|
| 1349 |
).success(
|
| 1350 |
+
fn=self.update_titles_after_import,
|
| 1351 |
inputs=[enable_automatic_video_split, enable_automatic_content_captioning, custom_prompt_prefix],
|
| 1352 |
outputs=[
|
| 1353 |
tabs, video_list, detect_status,
|
|
|
|
| 1360 |
inputs=[youtube_url],
|
| 1361 |
outputs=[import_status]
|
| 1362 |
).success(
|
| 1363 |
+
fn=self.on_import_success,
|
| 1364 |
inputs=[enable_automatic_video_split, enable_automatic_content_captioning, custom_prompt_prefix],
|
| 1365 |
outputs=[tabs, video_list, detect_status]
|
| 1366 |
)
|