BatuhanYilmaz commited on
Commit
900e8be
β€’
1 Parent(s): 49acb19

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +22 -4
app.py CHANGED
@@ -8,8 +8,11 @@ import streamlit as st
8
  from streamlit_lottie import st_lottie
9
  import numpy as np
10
  import os
 
 
 
11
 
12
- st.set_page_config(page_title="Youtube Transcriber", page_icon="πŸ—£", layout="wide")
13
 
14
 
15
  # Define a function that we can use to load lottie files from a link.
@@ -83,7 +86,22 @@ def inference(link):
83
  yt = YouTube(link)
84
  path = yt.streams.filter(only_audio=True)[0].download(filename="audio.mp4")
85
  results = loaded_model.transcribe(path)
86
- return results["text"]
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
87
 
88
 
89
  def main():
@@ -107,10 +125,10 @@ def main():
107
  st.write(description)
108
  #st.markdown(f"**Video Description**: {description}")
109
  with st.expander("Video Transcript"):
110
- st.write(results)
111
  # Write the results to a .txt file and download it.
112
  with open("transcript.txt", "w+") as f:
113
- f.writelines(results)
114
  f.close()
115
  with open(os.path.join(os.getcwd(), "transcript.txt"), "rb") as f:
116
  data = f.read()
 
8
  from streamlit_lottie import st_lottie
9
  import numpy as np
10
  import os
11
+ from typing import Iterator
12
+ from io import StringIO
13
+ from utils import write_vtt, write_srt
14
 
15
+ st.set_page_config(page_title="YouTube Transcriber", page_icon="πŸ—£", layout="wide")
16
 
17
 
18
  # Define a function that we can use to load lottie files from a link.
 
86
  yt = YouTube(link)
87
  path = yt.streams.filter(only_audio=True)[0].download(filename="audio.mp4")
88
  results = loaded_model.transcribe(path)
89
+ vtt = getSubs(results["segments"], "vtt", 80)
90
+ return results["text"], vtt
91
+
92
+ def getSubs(segments: Iterator[dict], format: str, maxLineWidth: int) -> str:
93
+ segmentStream = StringIO()
94
+
95
+ if format == 'vtt':
96
+ write_vtt(segments, file=segmentStream, maxLineWidth=maxLineWidth)
97
+ elif format == 'srt':
98
+ write_srt(segments, file=segmentStream, maxLineWidth=maxLineWidth)
99
+ else:
100
+ raise Exception("Unknown format " + format)
101
+
102
+ segmentStream.seek(0)
103
+ return segmentStream.read()
104
+
105
 
106
 
107
  def main():
 
125
  st.write(description)
126
  #st.markdown(f"**Video Description**: {description}")
127
  with st.expander("Video Transcript"):
128
+ st.write(results[0])
129
  # Write the results to a .txt file and download it.
130
  with open("transcript.txt", "w+") as f:
131
+ f.writelines(results[1])
132
  f.close()
133
  with open(os.path.join(os.getcwd(), "transcript.txt"), "rb") as f:
134
  data = f.read()