Spaces:
Running
Running
import json | |
from datetime import date | |
import webvtt | |
def get_seconds(time_str): | |
h, m, s_ms = time_str.split(':') | |
s, ms = s_ms.split('.') | |
return int(h) * 3600 + int(m) * 60 + int(s) + float('0.' + ms) | |
def get_transcript(path): | |
with open(path) as f: | |
transcript = f.read() | |
transcript = transcript.replace('\n', ' ') | |
return transcript | |
def get_captions_from_vtt(path): | |
vtt = webvtt.read(path) | |
return [{'start': get_seconds(caption.start), 'end': get_seconds(caption.end), 'text': caption.text} for caption in vtt] | |
def save_summary(summary, path, filename, config): | |
path.mkdir(parents=True, exist_ok=True) | |
with open(path / filename, "w+") as f: | |
f.write(summary) | |
with open(path / "config.txt", "w+") as f: | |
config["date"] = str(date.today()) | |
json.dump(config, f, indent=4) | |
print("Saved", path / filename) | |