JoshMe1 commited on
Commit
1e4f9e5
·
1 Parent(s): f4c9403

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -12
app.py CHANGED
@@ -35,6 +35,11 @@ def format_timestamp(t):
35
  mi = (t - int(t))*1000
36
  return f"{int(hh):02d}:{int(mm):02d}:{int(ss):02d},{int(mi):03d}"
37
 
 
 
 
 
 
38
  langs = ["None"] + sorted(list(whisper.tokenizer.LANGUAGES.values()))
39
  model_size = list(whisper._MODELS.keys())
40
 
@@ -49,17 +54,12 @@ st.markdown("Larger models are more accurate, but slower. For 1min video, it'll
49
  if st.button("Transcribe"):
50
  transcript = get_transcript(url, model_size, lang, format)
51
  st.text_area("Transcription of the video", transcript)
52
-
53
- if transcript:
54
- with st.spinner("Saving transcript..."):
55
- with open("transcript.srt", "w", encoding="utf-8") as f:
56
- f.write(transcript)
57
- st.success("Transcript saved as transcript.srt")
58
  if format == ".srt":
59
- st.download_button(
60
- "Download .srt file",
61
- data=transcript,
62
- file_name="transcript.srt",
63
- mime="text/plain"
64
- )
65
 
 
 
 
 
 
 
35
  mi = (t - int(t))*1000
36
  return f"{int(hh):02d}:{int(mm):02d}:{int(ss):02d},{int(mi):03d}"
37
 
38
+ def save_srt(transcript):
39
+ with open("transcript.srt", "w") as f:
40
+ f.write(transcript)
41
+ return True
42
+
43
  langs = ["None"] + sorted(list(whisper.tokenizer.LANGUAGES.values()))
44
  model_size = list(whisper._MODELS.keys())
45
 
 
54
  if st.button("Transcribe"):
55
  transcript = get_transcript(url, model_size, lang, format)
56
  st.text_area("Transcription of the video", transcript)
 
 
 
 
 
 
57
  if format == ".srt":
58
+ if save_srt(transcript):
59
+ st.markdown(get_srt_download_link("transcript.srt"), unsafe_allow_html=True)
 
 
 
 
60
 
61
+ def get_srt_download_link(file_path):
62
+ with open(file_path, "rb") as f:
63
+ srt = f.read().decode("utf-8")
64
+ href = f"<a href='data:text/plain;charset=utf-8,{srt}' download='transcript.srt'>Download .srt file</a>"
65
+ return href