Commit 49dc3c62 authored by De Silva K.C.C.C's avatar De Silva K.C.C.C

Topic API

parent 2ecf839d
# import libraries
from flask import Flask, request, send_file
from flask_cors import CORS
import json
import werkzeug
import os
import audio_gen as topic_gen
import bert as bert
from nltk.corpus import stopwords
s = set(stopwords.words('english'))
app = Flask(__name__)
CORS(app)
download_file = ''
@app.route('/topic', methods=['GET', 'POST'])
def topic():
imagefile = request.files['video']
filename = werkzeug.utils.secure_filename(imagefile.filename)
print("\nReceived image File name : " + imagefile.filename)
imagefile.save('upload/' + filename)
global download_file
download_file = 'upload/' + str(filename).replace('.mp4', '.txt')
text_list_from_video, all_text = topic_gen.split_video_file('upload/' + filename)
# Writing to a file
file1 = open(download_file, 'w')
file1.writelines(all_text)
file1.close()
topic_list = []
for index in text_list_from_video:
temp_topic = bert.get_topics_new(index[1])
filtered_topics = [elem for elem in temp_topic if elem not in s]
topic_list.append(filtered_topics[0])
return_json = '[ '
for i, topic in enumerate(topic_list):
if i == len(topic_list) - 1:
return_json += '{ "index" : "' + str(i) + '", "topic" : "' + str(topic) + '", "time_frame" : "' + str(
i * 240) + ' to end" } ]'
else:
return_json += '{ "index" : "' + str(i) + '", "topic" : "' + str(topic) + '", "time_frame" : "' + str(
i * 240) + ' to ' + str((i + 1) * 240) + ' seconds"} ,'
print(return_json)
return json.loads(return_json)
@app.route('/transcript', methods=['GET', 'POST'])
def transcript():
global download_file
doc = download_file
return send_file(doc, as_attachment=True)
if __name__ == "__main__":
app.run(host="0.0.0.0", port=1100, debug=True)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment