-
Notifications
You must be signed in to change notification settings - Fork 2
/
home.py
77 lines (55 loc) · 2.08 KB
/
home.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
import flask
import os
from flask import request, abort
from flask import send_file, send_from_directory
import video_structuring as vy
import deep_speech as deep_speech
import cmu_sphinx as cmu_sphinx
from flask_cors import CORS
from werkzeug.utils import secure_filename
app = flask.Flask(__name__)
CORS(app)
app.config["DEBUG"] = True
def combine(method, name):
path = "D:/Video_to_text/Files/"
video = name
audio, transcript = vy.home(path, video)
res = ""
if method=='deepspeech':
res = deep_speech.func(audio, transcript)
elif method=='cmu':
res = cmu_sphinx.func(audio, transcript)
return(res)
# API to generate the transcript and store it in the local path
@app.route('/generate_transcript', methods=['POST'])
def home():
#print(request.get_data())
print('form',request.form)
if 'file' not in request.files:
print('file',request.files)
abort(400)
elif 'method' not in request.form:
print('method',request.form)
abort(400)
file_request = request.files['file']
content_type_file = file_request.content_type
print(file_request)
print(request.form['method'])
if "video" in content_type_file:
print("video")
elif "audio" in content_type_file:
print("audio")
else:
abort(400)
filename = secure_filename(file_request.filename)
file_request.save(os.path.join('D:/Video_to_text/Files/Video', filename))
print("saved file successfully")
video_name = 'D:/Video_to_text/Files/Video/'+filename
print(video_name)
return(combine(request.form['method'], video_name))
# API to download the trancript from the local file system where it was stored
@app.route('/download_transcript', methods=['GET'])
def download():
return send_file(os.path.join('D:/Video_to_text/Files/Transcript/output.txt'), attachment_filename="output.txt", as_attachment=True)
if __name__ == '__main__':
app.run(host='0.0.0.0', port='5002')