v1
Browse files
app.py
CHANGED
@@ -152,43 +152,49 @@ class VideoHighlightDetector:
|
|
152 |
outputs = self.model.generate(**inputs, max_new_tokens=64, do_sample=False)
|
153 |
response = self.processor.decode(outputs[0], skip_special_tokens=True).lower().split("assistant: ")[1]
|
154 |
return "yes" in response
|
155 |
-
|
156 |
def create_xspf_playlist(video_path: str, segments: list, descriptions: list) -> str:
|
157 |
"""Create XSPF playlist from segments with descriptions."""
|
158 |
-
|
|
|
|
|
|
|
|
|
159 |
|
160 |
# Get video filename for the title
|
161 |
video_filename = os.path.basename(video_path)
|
162 |
-
title = ET.SubElement(root, "title")
|
163 |
title.text = f"{video_filename} - Highlights"
|
164 |
|
165 |
-
tracklist = ET.SubElement(root, "trackList")
|
166 |
|
167 |
for idx, ((start_time, end_time), description) in enumerate(zip(segments, descriptions)):
|
168 |
-
track = ET.SubElement(tracklist, "track")
|
169 |
|
170 |
-
location = ET.SubElement(track, "location")
|
171 |
location.text = f"file:///{video_filename}"
|
172 |
|
173 |
-
title = ET.SubElement(track, "title")
|
174 |
title.text = f"Highlight {idx + 1}"
|
175 |
|
176 |
-
annotation = ET.SubElement(track, "annotation")
|
177 |
annotation.text = description
|
178 |
|
179 |
-
start_meta = ET.SubElement(track, "meta", rel
|
180 |
start_meta.text = format_duration(start_time)
|
181 |
|
182 |
-
end_meta = ET.SubElement(track, "meta", rel
|
183 |
end_meta.text = format_duration(end_time)
|
184 |
|
185 |
# Add VLC extension
|
186 |
-
extension = ET.SubElement(root, "
|
|
|
|
|
187 |
for i in range(len(segments)):
|
188 |
-
|
|
|
189 |
|
190 |
# Convert to string with pretty printing
|
191 |
-
xml_str = minidom.parseString(ET.tostring(root)).toprettyxml(indent=" ")
|
192 |
return xml_str
|
193 |
|
194 |
def create_ui(examples_path: str, model_path: str):
|
@@ -280,6 +286,7 @@ def create_ui(examples_path: str, model_path: str):
|
|
280 |
|
281 |
if detector.process_segment(temp_segment.name, highlights):
|
282 |
# Get segment description
|
|
|
283 |
description = detector.analyze_segment(temp_segment.name)
|
284 |
kept_segments.append((start_time, end_time))
|
285 |
segment_descriptions.append(description)
|
|
|
152 |
outputs = self.model.generate(**inputs, max_new_tokens=64, do_sample=False)
|
153 |
response = self.processor.decode(outputs[0], skip_special_tokens=True).lower().split("assistant: ")[1]
|
154 |
return "yes" in response
|
|
|
155 |
def create_xspf_playlist(video_path: str, segments: list, descriptions: list) -> str:
|
156 |
"""Create XSPF playlist from segments with descriptions."""
|
157 |
+
# Register the VLC namespace
|
158 |
+
ET.register_namespace('vlc', 'http://www.videolan.org/vlc/playlist/ns/0/')
|
159 |
+
ET.register_namespace('', 'http://xspf.org/ns/0/')
|
160 |
+
|
161 |
+
root = ET.Element("{http://xspf.org/ns/0/}playlist", {"version": "1"})
|
162 |
|
163 |
# Get video filename for the title
|
164 |
video_filename = os.path.basename(video_path)
|
165 |
+
title = ET.SubElement(root, "{http://xspf.org/ns/0/}title")
|
166 |
title.text = f"{video_filename} - Highlights"
|
167 |
|
168 |
+
tracklist = ET.SubElement(root, "{http://xspf.org/ns/0/}trackList")
|
169 |
|
170 |
for idx, ((start_time, end_time), description) in enumerate(zip(segments, descriptions)):
|
171 |
+
track = ET.SubElement(tracklist, "{http://xspf.org/ns/0/}track")
|
172 |
|
173 |
+
location = ET.SubElement(track, "{http://xspf.org/ns/0/}location")
|
174 |
location.text = f"file:///{video_filename}"
|
175 |
|
176 |
+
title = ET.SubElement(track, "{http://xspf.org/ns/0/}title")
|
177 |
title.text = f"Highlight {idx + 1}"
|
178 |
|
179 |
+
annotation = ET.SubElement(track, "{http://xspf.org/ns/0/}annotation")
|
180 |
annotation.text = description
|
181 |
|
182 |
+
start_meta = ET.SubElement(track, "{http://xspf.org/ns/0/}meta", {"rel": "start"})
|
183 |
start_meta.text = format_duration(start_time)
|
184 |
|
185 |
+
end_meta = ET.SubElement(track, "{http://xspf.org/ns/0/}meta", {"rel": "end"})
|
186 |
end_meta.text = format_duration(end_time)
|
187 |
|
188 |
# Add VLC extension
|
189 |
+
extension = ET.SubElement(root, "{http://xspf.org/ns/0/}extension",
|
190 |
+
{"application": "http://www.videolan.org/vlc/playlist/0"})
|
191 |
+
|
192 |
for i in range(len(segments)):
|
193 |
+
ET.SubElement(extension, "{http://www.videolan.org/vlc/playlist/ns/0/}item",
|
194 |
+
{"tid": str(i)})
|
195 |
|
196 |
# Convert to string with pretty printing
|
197 |
+
xml_str = minidom.parseString(ET.tostring(root, encoding='unicode')).toprettyxml(indent=" ")
|
198 |
return xml_str
|
199 |
|
200 |
def create_ui(examples_path: str, model_path: str):
|
|
|
286 |
|
287 |
if detector.process_segment(temp_segment.name, highlights):
|
288 |
# Get segment description
|
289 |
+
print("KEEPING SEGMENT")
|
290 |
description = detector.analyze_segment(temp_segment.name)
|
291 |
kept_segments.append((start_time, end_time))
|
292 |
segment_descriptions.append(description)
|