iamacaru commited on
Commit
cfdbf22
·
verified ·
1 Parent(s): 1f6aa1e

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +37 -0
app.py ADDED
@@ -0,0 +1,37 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from flask import Flask, request, jsonify
2
+ from pytube import YouTube
3
+ import os
4
+
5
+ app = Flask(__name__)
6
+
7
+ @app.route('/', methods=['POST'])
8
+ def transcribe_video():
9
+ # Get YouTube video link from request data
10
+ youtube_link = request.json['youtube_link']
11
+
12
+ # Download the video
13
+ yt = YouTube(youtube_link)
14
+ video = yt.streams.filter().first()
15
+ destination = '.'
16
+ out_file = video.download(output_path=destination)
17
+
18
+ # Transcribe the video
19
+ base, ext = os.path.splitext(out_file)
20
+ aac_file_out = base + ".aac"
21
+ os.system(f"ffmpeg -i {out_file} -vn -acodec copy {aac_file_out}")
22
+ os.system(f"whisper {aac_file_out} --model medium --language Spanish --output_dir ./ --verbose False")
23
+
24
+ # Read the transcription
25
+ transcription_file = base + "_transcription.txt"
26
+ with open(transcription_file, 'r', encoding='utf-8') as file:
27
+ transcription = file.read()
28
+
29
+ # Clean up temporary files
30
+ os.remove(out_file)
31
+ os.remove(aac_file_out)
32
+ os.remove(transcription_file)
33
+
34
+ return jsonify({'transcription': transcription})
35
+
36
+ if __name__ == '__main__':
37
+ app.run(debug=True)