Commit b6f14a4a authored by chaveenagit's avatar chaveenagit

api

parent 3ee5a299
from flask import Flask, request, render_template, send_file
from flask_cors import CORS
import werkzeug
import cv2
import note_generator.note as note_gen
import topics_find.audio_gen as topic_gen
import note_generator.write_word as writer
import topics_find.bert as bert
import os
os.environ['KMP_DUPLICATE_LIB_OK']='True'
app = Flask(__name__)
CORS(app)
video_file_name = ''
pptx_file_name = ''
@app.route('/')
def index():
return render_template('index.html')
@app.route('/upload_action', methods=['GET', 'POST'])
def upload_action():
lecture_video = request.files['lecture_video']
filename_v = werkzeug.utils.secure_filename(lecture_video.filename)
print("\nReceived image File name : " + lecture_video.filename)
lecture_video.save('upload/' + filename_v)
lecture_ppt = request.files['lecture_ppt']
filename = werkzeug.utils.secure_filename(lecture_ppt.filename)
print("\nReceived image File name : " + lecture_ppt.filename)
lecture_ppt.save('upload/' + filename)
global video_file_name
global pptx_file_name
video_file_name = filename_v
pptx_file_name = filename
return render_template('upload.html', video_file_name=video_file_name, pptx_file_name=pptx_file_name)
@app.route('/generate_topics', methods=['GET', 'POST'])
def generate_topics():
global video_file_name
global pptx_file_name
text_list_from_video, all_text = topic_gen.split_video_file('upload/' + video_file_name)
topic_list = []
for index in text_list_from_video:
topic_list.append([index[0], index[1], bert.get_topics_new(index[1])])
return render_template('topics.html', topic_list=topic_list)
@app.route('/generate_short_note', methods=['GET', 'POST'])
def generate_short_note():
global video_file_name
global pptx_file_name
text_from_pptx = note_gen.generate_note('upload/' + pptx_file_name)
text_list_from_video, all_text = topic_gen.split_video_file('upload/' + video_file_name)
writer.create_doc()
writer.write_note('short note from lecture video :- ')
for i in text_list_from_video:
writer.write_note(i[1])
writer.write_note('short note from lecture slide (pptx) :- ')
writer.write_note(text_from_pptx)
writer.save_note('upload/' + pptx_file_name.split('.')[0] + '.docx')
doc_filename = pptx_file_name.split('.')[0] + '.docx'
print(doc_filename)
return render_template('short_notes.html', filename=doc_filename)
@app.route('/short_note/<name>')
def short_note(name):
doc = 'upload/' + name
print('request', doc)
return send_file(doc, as_attachment=True)
if __name__ == '__main__':
app.run(host="0.0.0.0", port=5200, 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