-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
34 lines (25 loc) · 1.19 KB
/
app.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
from flask import Flask, render_template, request, jsonify
from markupsafe import Markup
from youtube_services.get_transcript import get_transcript_by_url, convert_timestamped_transcript_to_text, translate_text
from utils.utils import get_video_id_from_url, get_embed_url_from_video_id
import logging
logging.basicConfig(level=logging.INFO,
format='%(asctime)s - %(levelname)s - %(message)s',
filename='app.log',
filemode='w')
logger = logging.getLogger(__name__)
app = Flask(__name__, template_folder='site/templates', static_folder='site/static')
@app.route('/')
def home():
return render_template('index.html')
@app.route('/translate')
def translate():
data = request.args
url = data.get('video-url')
video_id = get_video_id_from_url(url)
embed_url = get_embed_url_from_video_id(video_id)
translated_transcript = translate_text(get_transcript_by_url(url))
return render_template('index.html', video_id=video_id, embed_url=embed_url, translated_transcript=Markup(translated_transcript))
if __name__ == '__main__':
logger.info('Starting Flask app')
app.run(debug=True, port=8000, host='0.0.0.0')