mfarre HF staff commited on
Commit
c77c2d5
·
1 Parent(s): 97072ea
Files changed (1) hide show
  1. app.py +29 -44
app.py CHANGED
@@ -157,56 +157,41 @@ class VideoHighlightDetector:
157
  outputs = self.model.generate(**inputs, max_new_tokens=64, do_sample=False)
158
  response = self.processor.decode(outputs[0], skip_special_tokens=True).lower().split("assistant: ")[1]
159
  return "yes" in response
 
160
  def create_xspf_playlist(video_path: str, segments: list, descriptions: list) -> str:
161
  """Create XSPF playlist from segments with descriptions."""
162
- # Register namespaces to avoid namespace prefix issues
163
- ET.register_namespace('', "http://xspf.org/ns/0/")
164
- ET.register_namespace('vlc', "http://www.videolan.org/vlc/playlist/ns/0/")
165
-
166
- # Create the root element with proper namespace
167
- root = ET.Element("{http://xspf.org/ns/0/}playlist", {
168
- "version": "1"
169
- })
170
-
171
- # Get video filename for the title
172
- video_filename = os.path.basename(video_path)
173
- title = ET.SubElement(root, "{http://xspf.org/ns/0/}title")
174
- title.text = f"{video_filename} - Highlights"
175
 
176
- tracklist = ET.SubElement(root, "{http://xspf.org/ns/0/}trackList")
 
 
 
 
 
 
177
 
178
  for idx, ((start_time, end_time), description) in enumerate(zip(segments, descriptions)):
179
- track = ET.SubElement(tracklist, "{http://xspf.org/ns/0/}track")
180
-
181
- location = ET.SubElement(track, "{http://xspf.org/ns/0/}location")
182
- location.text = f"file:///{video_filename}"
183
-
184
- title = ET.SubElement(track, "{http://xspf.org/ns/0/}title")
185
- title.text = f"Highlight {idx + 1}: {description}"
186
-
187
- annotation = ET.SubElement(track, "{http://xspf.org/ns/0/}annotation")
188
- annotation.text = description
189
-
190
- start_meta = ET.SubElement(track, "{http://xspf.org/ns/0/}meta")
191
- start_meta.set("rel", "start")
192
- start_meta.text = format_duration(start_time)
193
-
194
- end_meta = ET.SubElement(track, "{http://xspf.org/ns/0/}meta")
195
- end_meta.set("rel", "end")
196
- end_meta.text = format_duration(end_time)
197
-
198
- # Add VLC extension with proper namespace
199
- extension = ET.SubElement(root, "{http://xspf.org/ns/0/}extension")
200
- extension.set("application", "http://www.videolan.org/vlc/playlist/0")
201
-
202
- for i in range(len(segments)):
203
- item = ET.SubElement(extension, "{http://www.videolan.org/vlc/playlist/ns/0/}item")
204
- item.set("tid", str(i))
205
 
206
- # Convert to string with pretty printing
207
- xml_str = minidom.parseString(ET.tostring(root, encoding='unicode')).toprettyxml(indent=" ")
 
 
208
 
209
- return xml_str
210
 
211
  def create_ui(examples_path: str, model_path: str):
212
  examples_data = load_examples(examples_path)
@@ -263,7 +248,7 @@ def create_ui(examples_path: str, model_path: str):
263
 
264
  try:
265
  duration = get_video_duration_seconds(video)
266
- if duration > 1800: # 30 minutes
267
  return [
268
  None,
269
  "Video must be shorter than 30 minutes",
 
157
  outputs = self.model.generate(**inputs, max_new_tokens=64, do_sample=False)
158
  response = self.processor.decode(outputs[0], skip_special_tokens=True).lower().split("assistant: ")[1]
159
  return "yes" in response
160
+
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.abspath(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>{os.path.basename(video_path)} - Highlights</title>',
171
+ ' <trackList>'
172
+ ]
173
 
174
  for idx, ((start_time, end_time), description) in enumerate(zip(segments, descriptions)):
175
+ track = [
176
+ ' <track>',
177
+ f' <location>file:///{video_filename}</location>',
178
+ f' <title>Highlight {idx + 1}</title>',
179
+ f' <annotation>{description}</annotation>',
180
+ ' <extension application="http://www.videolan.org/vlc/playlist/0">',
181
+ f' <vlc:id>{idx}</vlc:id>',
182
+ f' <vlc:option>start-time={int(start_time)}</vlc:option>',
183
+ f' <vlc:option>stop-time={int(end_time)}</vlc:option>',
184
+ ' </extension>',
185
+ ' </track>'
186
+ ]
187
+ xml_content.extend(track)
 
 
 
 
 
 
 
 
 
 
 
 
 
188
 
189
+ xml_content.extend([
190
+ ' </trackList>',
191
+ '</playlist>'
192
+ ])
193
 
194
+ return '\n'.join(xml_content)
195
 
196
  def create_ui(examples_path: str, model_path: str):
197
  examples_data = load_examples(examples_path)
 
248
 
249
  try:
250
  duration = get_video_duration_seconds(video)
251
+ if duration > 18000: # 30 minutes
252
  return [
253
  None,
254
  "Video must be shorter than 30 minutes",