Spaces:
Build error
Build error
Miquel Farre
commited on
Commit
·
bfcc0a3
1
Parent(s):
c77c2d5
fixes
Browse files
app.py
CHANGED
|
@@ -161,13 +161,13 @@ class VideoHighlightDetector:
|
|
| 161 |
def create_xspf_playlist(video_path: str, segments: list, descriptions: list) -> str:
|
| 162 |
"""Create XSPF playlist from segments with descriptions."""
|
| 163 |
# Get video filename with full path
|
| 164 |
-
video_filename = os.path.
|
| 165 |
|
| 166 |
# Create the XML structure as a string
|
| 167 |
xml_content = [
|
| 168 |
'<?xml version="1.0" encoding="UTF-8"?>',
|
| 169 |
'<playlist version="1" xmlns="http://xspf.org/ns/0/" xmlns:vlc="http://www.videolan.org/vlc/playlist/0/">',
|
| 170 |
-
f' <title>{
|
| 171 |
' <trackList>'
|
| 172 |
]
|
| 173 |
|
|
@@ -175,7 +175,7 @@ def create_xspf_playlist(video_path: str, segments: list, descriptions: list) ->
|
|
| 175 |
track = [
|
| 176 |
' <track>',
|
| 177 |
f' <location>file:///{video_filename}</location>',
|
| 178 |
-
f' <title>
|
| 179 |
f' <annotation>{description}</annotation>',
|
| 180 |
' <extension application="http://www.videolan.org/vlc/playlist/0">',
|
| 181 |
f' <vlc:id>{idx}</vlc:id>',
|
|
@@ -257,12 +257,36 @@ def create_ui(examples_path: str, model_path: str):
|
|
| 257 |
gr.update(visible=False)
|
| 258 |
]
|
| 259 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 260 |
detector = VideoHighlightDetector(model_path=model_path)
|
| 261 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 262 |
# Analyze video content
|
| 263 |
video_desc = detector.analyze_video_content(video)
|
| 264 |
formatted_desc = f"### Video Summary:\n{video_desc}"
|
| 265 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 266 |
# Determine highlight types
|
| 267 |
highlights = detector.determine_highlights(video_desc)
|
| 268 |
formatted_highlights = f"### Highlight Criteria:\n{highlights}"
|
|
@@ -271,9 +295,21 @@ def create_ui(examples_path: str, model_path: str):
|
|
| 271 |
segment_length = 10.0
|
| 272 |
kept_segments = []
|
| 273 |
segment_descriptions = []
|
| 274 |
-
|
|
|
|
|
|
|
| 275 |
for start_time in range(0, int(duration), int(segment_length)):
|
| 276 |
end_time = min(start_time + segment_length, duration)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 277 |
|
| 278 |
# Create temporary segment
|
| 279 |
with tempfile.NamedTemporaryFile(suffix='.mp4') as temp_segment:
|
|
@@ -306,7 +342,7 @@ def create_ui(examples_path: str, model_path: str):
|
|
| 306 |
|
| 307 |
return [
|
| 308 |
gr.update(value=playlist_path, visible=True),
|
| 309 |
-
"Processing complete!
|
| 310 |
formatted_desc,
|
| 311 |
formatted_highlights,
|
| 312 |
gr.update(visible=True)
|
|
|
|
| 161 |
def create_xspf_playlist(video_path: str, segments: list, descriptions: list) -> str:
|
| 162 |
"""Create XSPF playlist from segments with descriptions."""
|
| 163 |
# Get video filename with full path
|
| 164 |
+
video_filename = os.path.basename(video_path)
|
| 165 |
|
| 166 |
# Create the XML structure as a string
|
| 167 |
xml_content = [
|
| 168 |
'<?xml version="1.0" encoding="UTF-8"?>',
|
| 169 |
'<playlist version="1" xmlns="http://xspf.org/ns/0/" xmlns:vlc="http://www.videolan.org/vlc/playlist/0/">',
|
| 170 |
+
f' <title>{video_filename} - Highlights</title>',
|
| 171 |
' <trackList>'
|
| 172 |
]
|
| 173 |
|
|
|
|
| 175 |
track = [
|
| 176 |
' <track>',
|
| 177 |
f' <location>file:///{video_filename}</location>',
|
| 178 |
+
f' <title>{description}</title>',
|
| 179 |
f' <annotation>{description}</annotation>',
|
| 180 |
' <extension application="http://www.videolan.org/vlc/playlist/0">',
|
| 181 |
f' <vlc:id>{idx}</vlc:id>',
|
|
|
|
| 257 |
gr.update(visible=False)
|
| 258 |
]
|
| 259 |
|
| 260 |
+
yield [
|
| 261 |
+
"Initializing video highlight detector...",
|
| 262 |
+
"",
|
| 263 |
+
"",
|
| 264 |
+
gr.update(visible=False),
|
| 265 |
+
gr.update(visible=False)
|
| 266 |
+
]
|
| 267 |
+
|
| 268 |
detector = VideoHighlightDetector(model_path=model_path)
|
| 269 |
+
|
| 270 |
+
yield [
|
| 271 |
+
"Analyzing video content...",
|
| 272 |
+
"",
|
| 273 |
+
"",
|
| 274 |
+
gr.update(visible=False),
|
| 275 |
+
gr.update(visible=True)
|
| 276 |
+
]
|
| 277 |
+
|
| 278 |
# Analyze video content
|
| 279 |
video_desc = detector.analyze_video_content(video)
|
| 280 |
formatted_desc = f"### Video Summary:\n{video_desc}"
|
| 281 |
+
|
| 282 |
+
yield [
|
| 283 |
+
"Determining highlight types...",
|
| 284 |
+
formatted_desc,
|
| 285 |
+
"",
|
| 286 |
+
gr.update(visible=False),
|
| 287 |
+
gr.update(visible=True)
|
| 288 |
+
]
|
| 289 |
+
|
| 290 |
# Determine highlight types
|
| 291 |
highlights = detector.determine_highlights(video_desc)
|
| 292 |
formatted_highlights = f"### Highlight Criteria:\n{highlights}"
|
|
|
|
| 295 |
segment_length = 10.0
|
| 296 |
kept_segments = []
|
| 297 |
segment_descriptions = []
|
| 298 |
+
segments_processed = 0
|
| 299 |
+
total_segments = int(duration / segment_length)
|
| 300 |
+
|
| 301 |
for start_time in range(0, int(duration), int(segment_length)):
|
| 302 |
end_time = min(start_time + segment_length, duration)
|
| 303 |
+
segments_processed +=1
|
| 304 |
+
progress = int((segments_processed / total_segments) * 100)
|
| 305 |
+
|
| 306 |
+
yield [
|
| 307 |
+
f"Processing segments... {progress}% complete",
|
| 308 |
+
formatted_desc,
|
| 309 |
+
formatted_highlights,
|
| 310 |
+
gr.update(visible=False),
|
| 311 |
+
gr.update(visible=True)
|
| 312 |
+
]
|
| 313 |
|
| 314 |
# Create temporary segment
|
| 315 |
with tempfile.NamedTemporaryFile(suffix='.mp4') as temp_segment:
|
|
|
|
| 342 |
|
| 343 |
return [
|
| 344 |
gr.update(value=playlist_path, visible=True),
|
| 345 |
+
"Processing complete! You can download the playlist.",
|
| 346 |
formatted_desc,
|
| 347 |
formatted_highlights,
|
| 348 |
gr.update(visible=True)
|