BatuhanYilmaz commited on
Commit
153763d
1 Parent(s): 900e8be

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +34 -7
app.py CHANGED
@@ -87,7 +87,8 @@ def inference(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()
@@ -103,7 +104,6 @@ def getSubs(segments: Iterator[dict], format: str, maxLineWidth: int) -> str:
103
  return segmentStream.read()
104
 
105
 
106
-
107
  def main():
108
  change_model(current_size, size)
109
  link = st.text_input("YouTube Link")
@@ -127,15 +127,42 @@ def main():
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()
135
- if st.download_button(label="Download Transcript",
136
- data=data,
137
- file_name="transcript.txt"):
138
- st.success("Downloaded Successfully!")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
139
 
140
  if __name__ == "__main__":
141
  main()
 
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
+ srt = getSubs(results["segments"], "srt", 80)
91
+ return results["text"], vtt, srt
92
 
93
  def getSubs(segments: Iterator[dict], format: str, maxLineWidth: int) -> str:
94
  segmentStream = StringIO()
 
104
  return segmentStream.read()
105
 
106
 
 
107
  def main():
108
  change_model(current_size, size)
109
  link = st.text_input("YouTube Link")
 
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[0])
132
+ f.close()
133
+ with open(os.path.join(os.getcwd(), "transcript.txt"), "rb") as f:
134
+ datatxt = f.read()
135
+
136
+
137
  with open("transcript.txt", "w+") as f:
138
  f.writelines(results[1])
139
  f.close()
140
  with open(os.path.join(os.getcwd(), "transcript.txt"), "rb") as f:
141
+ datavtt = f.read()
142
+
143
+ with open("transcript.txt", "w+") as f:
144
+ f.writelines(results[2])
145
+ f.close()
146
+ with open(os.path.join(os.getcwd(), "transcript.txt"), "rb") as f:
147
+ datasrt = f.read()
148
+
149
+ if st.download_button(label="Download Transcript (.txt)",
150
+ data=datatxt,
151
+ file_name=f"{title}.txt"):
152
+ st.success("Downloaded Successfully!")
153
+
154
+ elif st.download_button(label="Download Transcript (.vtt)",
155
+ data=datavtt,
156
+ file_name=f"{title}.vtt"):
157
+ st.success("Downloaded Successfully!")
158
+
159
+ elif st.download_button(label="Download Transcript (.srt)",
160
+ data=datasrt,
161
+ file_name=f"{title}.srt"):
162
+ st.success("Downloaded Successfully!")
163
+ else:
164
+ # Keep the page on after the download button is clicked.,
165
+ st.info("Streamlit refreshes after the download button is clicked. The data is cached so you can download the transcript again without having to transcribe the video again.")
166
 
167
  if __name__ == "__main__":
168
  main()