podcast / main.py
Yannael_LB
Update
bfae900
from flask import Flask, render_template, request
#from youtube_transcript_api import YouTubeTranscriptApi
import json
app = Flask(__name__)
def summarize_text_1(chunk):
# Return the first line of the text chunk
return chunk[0] if chunk else ""
def summarize_text_2(chunk):
# Return the first two lines of the text chunk
return "\n".join(chunk[:2]) if chunk else ""
def summarize_text_3(chunk):
# Return the first three lines of the text chunk
return "\n".join(chunk[:3]) if chunk else ""
def load_transcript_data():
with open('transcript_data.json', 'r') as file:
transcript_data = json.load(file)
return transcript_data
@app.route('/', methods=['GET', 'POST'])
def index():
transcripts = []
if request.method == 'POST':
video_id = request.form.get('video_id')
language = request.form.get('language')
try:
#transcript_list = YouTubeTranscriptApi.get_transcript(video_id, languages=[language])
#full_transcript = "\n".join([i['text'] for i in transcript_list])
#lines = full_transcript.split('\n')
#chunks = [lines[i:i + 10] for i in range(0, len(lines), 10)]
chunks = load_transcript_data()
# Apply summarization functions
transcripts = [
{
'full_text': '\n'.join("a"),
'summary_1': chunk['summary1'],
'summary_2': chunk['summary2'],
'summary_3': chunk['transcript'],
'timestamp': chunk['start']
} for chunk in chunks
]
except Exception as e:
transcripts = [{'full_text': f"An error occurred: {str(e)}", 'summary_1': "Error", 'summary_2': "Error", 'summary_3': "Error"}]
return render_template('index.html', transcripts=transcripts)
if __name__ == '__main__':
app.run(debug=True)