-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
25 lines (21 loc) · 906 Bytes
/
Copy pathapp.py
File metadata and controls
25 lines (21 loc) · 906 Bytes
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
from flask import Flask, render_template, request, jsonify
from transcript_bot import TranscriptBot
app = Flask(__name__)
bot = TranscriptBot()
@app.route('/', methods=['GET', 'POST'])
def index():
if request.method == 'POST':
video_url = request.form['video_url']
video_id = bot.get_video_id(video_url)
transcript = bot.fetch_and_fit_transcript(video_id)
bot.save_transcript_to_file(video_id)
return render_template('chat.html')
return render_template('index.html')
@app.route('/chat', methods=['POST'])
def chat():
user_input = request.form['user_input']
transcript_file = open(f"{bot.get_video_id(request.form['video_url'])}_transcript.txt", 'r', encoding='utf-8').read()
response = bot.generate_response(user_input, transcript_file)
return jsonify({'response': response})
if __name__ == '__main__':
app.run(debug=True, port=9000)