throaway2854 commited on
Commit
398bf21
·
verified ·
1 Parent(s): fea54d0

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +25 -1
app.py CHANGED
@@ -7,6 +7,7 @@ import huggingface_hub
7
  import numpy as np
8
  import onnxruntime as rt
9
  import pandas as pd
 
10
  from PIL import Image
11
 
12
  TITLE = "Video Tagger"
@@ -67,6 +68,20 @@ kaomojis = [
67
  ]
68
 
69
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
70
  def load_labels(df: pd.DataFrame):
71
  """
72
  Convert tag dataframe into:
@@ -587,6 +602,8 @@ def tag_video_interface(
587
  if video_path is None:
588
  return "", {"error": "Please upload a video file."}
589
 
 
 
590
  try:
591
  # Get or create the cached VideoTagger for this model,
592
  # and update its batch size for this run.
@@ -595,7 +612,7 @@ def tag_video_interface(
595
  tag_substitutes = _normalize_tag_substitutes(tag_substitutes_df)
596
  tag_exclusions = _normalize_tag_exclusions(tag_exclusions_df)
597
 
598
- return tagger.tag_video(
599
  video_path=video_path,
600
  frame_interval=frame_interval,
601
  general_thresh=general_thresh,
@@ -604,6 +621,13 @@ def tag_video_interface(
604
  tag_exclusions=tag_exclusions,
605
  progress=progress,
606
  )
 
 
 
 
 
 
 
607
  except Exception as e:
608
  return "", {"error": str(e)}
609
 
 
7
  import numpy as np
8
  import onnxruntime as rt
9
  import pandas as pd
10
+ import time
11
  from PIL import Image
12
 
13
  TITLE = "Video Tagger"
 
68
  ]
69
 
70
 
71
+ def _format_duration(seconds: float) -> str:
72
+ """
73
+ Format a duration in seconds as MM:SS or HH:MM:SS.
74
+ """
75
+ total_seconds = int(round(seconds))
76
+ hours, rem = divmod(total_seconds, 3600)
77
+ minutes, secs = divmod(rem, 60)
78
+
79
+ if hours > 0:
80
+ return f"{hours:02d}:{minutes:02d}:{secs:02d}"
81
+ else:
82
+ return f"{minutes:02d}:{secs:02d}"
83
+
84
+
85
  def load_labels(df: pd.DataFrame):
86
  """
87
  Convert tag dataframe into:
 
602
  if video_path is None:
603
  return "", {"error": "Please upload a video file."}
604
 
605
+ start_time = time.time()
606
+
607
  try:
608
  # Get or create the cached VideoTagger for this model,
609
  # and update its batch size for this run.
 
612
  tag_substitutes = _normalize_tag_substitutes(tag_substitutes_df)
613
  tag_exclusions = _normalize_tag_exclusions(tag_exclusions_df)
614
 
615
+ combined_tags_str, debug_info = tagger.tag_video(
616
  video_path=video_path,
617
  frame_interval=frame_interval,
618
  general_thresh=general_thresh,
 
621
  tag_exclusions=tag_exclusions,
622
  progress=progress,
623
  )
624
+
625
+ elapsed = time.time() - start_time
626
+ debug_info["session_duration_seconds"] = round(elapsed, 3)
627
+ debug_info["session_duration_hms"] = _format_duration(elapsed)
628
+
629
+ return combined_tags_str, debug_info
630
+
631
  except Exception as e:
632
  return "", {"error": str(e)}
633