Spaces:
Build error
Build error
Miquel Farre
commited on
Commit
·
97072ea
1
Parent(s):
146e842
fixes
Browse files
app.py
CHANGED
|
@@ -157,71 +157,73 @@ 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 |
-
|
| 161 |
def create_xspf_playlist(video_path: str, segments: list, descriptions: list) -> str:
|
| 162 |
"""Create XSPF playlist from segments with descriptions."""
|
| 163 |
-
#
|
| 164 |
-
|
| 165 |
-
|
| 166 |
|
| 167 |
# Create the root element with proper namespace
|
| 168 |
-
root = ET.Element("playlist", {
|
| 169 |
-
"xmlns": XSPF_NS,
|
| 170 |
-
"xmlns:vlc": VLC_NS,
|
| 171 |
"version": "1"
|
| 172 |
})
|
| 173 |
|
| 174 |
# Get video filename for the title
|
| 175 |
video_filename = os.path.basename(video_path)
|
| 176 |
-
title = ET.SubElement(root, "title")
|
| 177 |
title.text = f"{video_filename} - Highlights"
|
| 178 |
|
| 179 |
-
tracklist = ET.SubElement(root, "trackList")
|
| 180 |
|
| 181 |
for idx, ((start_time, end_time), description) in enumerate(zip(segments, descriptions)):
|
| 182 |
-
track = ET.SubElement(tracklist, "track")
|
| 183 |
|
| 184 |
-
location = ET.SubElement(track, "location")
|
| 185 |
location.text = f"file:///{video_filename}"
|
| 186 |
|
| 187 |
-
title = ET.SubElement(track, "title")
|
| 188 |
title.text = f"Highlight {idx + 1}: {description}"
|
| 189 |
|
| 190 |
-
annotation = ET.SubElement(track, "annotation")
|
| 191 |
annotation.text = description
|
| 192 |
|
| 193 |
-
start_meta = ET.SubElement(track, "meta")
|
| 194 |
start_meta.set("rel", "start")
|
| 195 |
start_meta.text = format_duration(start_time)
|
| 196 |
|
| 197 |
-
end_meta = ET.SubElement(track, "meta")
|
| 198 |
end_meta.set("rel", "end")
|
| 199 |
end_meta.text = format_duration(end_time)
|
| 200 |
|
| 201 |
-
# Add VLC extension
|
| 202 |
-
extension = ET.SubElement(root, "extension")
|
| 203 |
extension.set("application", "http://www.videolan.org/vlc/playlist/0")
|
| 204 |
|
| 205 |
for i in range(len(segments)):
|
| 206 |
-
item = ET.SubElement(extension, "{
|
| 207 |
item.set("tid", str(i))
|
| 208 |
|
| 209 |
# Convert to string with pretty printing
|
| 210 |
xml_str = minidom.parseString(ET.tostring(root, encoding='unicode')).toprettyxml(indent=" ")
|
| 211 |
|
| 212 |
-
# Clean up any potential namespace declaration issues
|
| 213 |
-
xml_str = xml_str.replace('xmlns:ns0="http://www.videolan.org/vlc/playlist/ns/0/"', '')
|
| 214 |
-
xml_str = xml_str.replace('ns0:', 'vlc:')
|
| 215 |
-
|
| 216 |
return xml_str
|
| 217 |
|
| 218 |
def create_ui(examples_path: str, model_path: str):
|
| 219 |
examples_data = load_examples(examples_path)
|
| 220 |
|
| 221 |
with gr.Blocks() as app:
|
| 222 |
-
gr.Markdown("#
|
| 223 |
-
gr.Markdown("Upload a video and get
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 224 |
|
|
|
|
|
|
|
| 225 |
with gr.Row():
|
| 226 |
with gr.Column(scale=1):
|
| 227 |
input_video = gr.Video(
|
|
|
|
| 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)
|
| 213 |
|
| 214 |
with gr.Blocks() as app:
|
| 215 |
+
# gr.Markdown("# VLC Highlight Generator")
|
| 216 |
+
# gr.Markdown("Upload a video and get a list of highlights!")
|
| 217 |
+
with gr.Row():
|
| 218 |
+
gr.HTML("""
|
| 219 |
+
<div style="display: flex; align-items: center; gap: 10px;">
|
| 220 |
+
<img src="https://upload.wikimedia.org/wikipedia/commons/3/38/VLC_icon.png" style="width: 40px; height: 40px;"/>
|
| 221 |
+
<h1 style="margin: 0;">VLC Highlight Generator</h1>
|
| 222 |
+
</div>
|
| 223 |
+
""")
|
| 224 |
|
| 225 |
+
gr.Markdown("Upload a video and get a list of highlights!")
|
| 226 |
+
|
| 227 |
with gr.Row():
|
| 228 |
with gr.Column(scale=1):
|
| 229 |
input_video = gr.Video(
|