Spaces:
Build error
Build error
Miquel Farre commited on
Commit ·
c77c2d5
1
Parent(s): 97072ea
fixes
Browse files156 unmodified lines15715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121250 unmodified lines263264265266267268269156 unmodified linesoutputs = self.model.generate(**inputs, max_new_tokens=64, do_sample=False)response = self.processor.decode(outputs[0], skip_special_tokens=True).lower().split("assistant: ")[1]return "yes" in responsedef create_xspf_playlist(video_path: str, segments: list, descriptions: list) -> str:"""Create XSPF playlist from segments with descriptions."""# Register namespaces to avoid namespace prefix issuesET.register_namespace('', "http://xspf.org/ns/0/")ET.register_namespace('vlc', "http://www.videolan.org/vlc/playlist/ns/0/")# Create the root element with proper namespaceroot = ET.Element("{http://xspf.org/ns/0/}playlist", {"version": "1"})# Get video filename for the titlevideo_filename = os.path.basename(video_path)title = ET.SubElement(root, "{http://xspf.org/ns/0/}title")title.text = f"{video_filename} - Highlights"tracklist = ET.SubElement(root, "{http://xspf.org/ns/0/}trackList")for idx, ((start_time, end_time), description) in enumerate(zip(segments, descriptions)):track = ET.SubElement(tracklist, "{http://xspf.org/ns/0/}track")location = ET.SubElement(track, "{http://xspf.org/ns/0/}location")location.text = f"file:///{video_filename}"title = ET.SubElement(track, "{http://xspf.org/ns/0/}title")title.text = f"Highlight {idx + 1}: {description}"annotation = ET.SubElement(track, "{http://xspf.org/ns/0/}annotation")annotation.text = descriptionstart_meta = ET.SubElement(track, "{http://xspf.org/ns/0/}meta")start_meta.set("rel", "start")start_meta.text = format_duration(start_time)end_meta = ET.SubElement(track, "{http://xspf.org/ns/0/}meta")end_meta.set("rel", "end")end_meta.text = format_duration(end_time)# Add VLC extension with proper namespaceextension = ET.SubElement(root, "{http://xspf.org/ns/0/}extension")extension.set("application", "http://www.videolan.org/vlc/playlist/0")for i in range(len(segments)):item = ET.SubElement(extension, "{http://www.videolan.org/vlc/playlist/ns/0/}item")item.set("tid", str(i))# Convert to string with pretty printingxml_str = minidom.parseString(ET.tostring(root, encoding='unicode')).toprettyxml(indent=" ")return xml_strdef create_ui(examples_path: str, model_path: str):examples_data = load_examples(examples_path)50 unmodified linestry:duration = get_video_duration_seconds(video)if duration > 1800: # 30 minutesreturn [None,"Video must be shorter than 30 minutes",156 unmodified lines15715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619750 unmodified lines248249250251252253254156 unmodified linesoutputs = self.model.generate(**inputs, max_new_tokens=64, do_sample=False)response = self.processor.decode(outputs[0], skip_special_tokens=True).lower().split("assistant: ")[1]return "yes" in responsedef create_xspf_playlist(video_path: str, segments: list, descriptions: list) -> str:"""Create XSPF playlist from segments with descriptions."""# Get video filename with full pathvideo_filename = os.path.abspath(video_path)# Create the XML structure as a stringxml_content = ['<?xml version="1.0" encoding="UTF-8"?>','<playlist version="1" xmlns="http://xspf.org/ns/0/" xmlns:vlc="http://www.videolan.org/vlc/playlist/0/">',f' <title>{os.path.basename(video_path)} - Highlights</title>',' <trackList>']for idx, ((start_time, end_time), description) in enumerate(zip(segments, descriptions)):track = [' <track>',f' <location>file:///{video_filename}</location>',f' <title>Highlight {idx + 1}</title>',f' <annotation>{description}</annotation>',' <extension application="http://www.videolan.org/vlc/playlist/0">',f' <vlc:id>{idx}</vlc:id>',f' <vlc:option>start-time={int(start_time)}</vlc:option>',f' <vlc:option>stop-time={int(end_time)}</vlc:option>',' </extension>',' </track>']xml_content.extend(track)xml_content.extend([' </trackList>','</playlist>'])return '\n'.join(xml_content)def create_ui(examples_path: str, model_path: str):examples_data = load_examples(examples_path)50 unmodified linestry:duration = get_video_duration_seconds(video)if duration > 18000: # 30 minutesreturn [None,"Video must be shorter than 30 minutes",
app.py+29-44