-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathhello.py
95 lines (72 loc) · 2.79 KB
/
hello.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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
from flask import Flask, render_template, request
from youtube_transcript_api import YouTubeTranscriptApi
from collections import Counter
from summarize import get_summary
from model import summarize_text
import moviepy.editor as mp
import speech_recognition as sr
# Load the video
from werkzeug.utils import secure_filename
import os
from rake_nltk import Rake
UPLOAD_FOLDER = './audiofiles'
app = Flask(__name__)
app.config['UPLOAD_FOLDER'] = UPLOAD_FOLDER
@app.route("/")
def home():
title = "hi"
message = "simple msg"
return render_template('input_form.html', title=title, message=message)
@app.route('/get_transcript', methods=['POST'])
def get_transcript():
youtube_link = request.form['youtube_link']
video_id = youtube_link.split('=')[1]
try:
transcript = YouTubeTranscriptApi.get_transcript(video_id)
transcript_text = ' '.join([entry['text'] for entry in transcript])
except Exception as e:
transcript_text = f"Error: {str(e)}"
#new_summary = get_summary(transcript_text)
sum = summarize_text(transcript_text)
return render_template('transcript.html', transcript=sum, original_transcript=transcript_text)
sum = summarize_text(transcript_text)
#new_summary = get_summary(transcript_text, percentage)
return render_template('transcript.html', transcript=sum, original_transcript=transcript_text)
@app.route('/key-concepts', methods=['POST'])
def get_common_words():
r = Rake()
transcript_text = request.form['transcript']
# words = transcript_text.lower().split()
# common_words = Counter(words).most_common(20) # Get the 10 most common words
r.extract_keywords_from_text(transcript_text)
keywords = r.get_ranked_phrases()[0:10]
return render_template('common_words.html', common_words=keywords)
@app.route('/transcript_file', methods=['POST'])
def transcript_file():
file = request.files['file']
filename = secure_filename(file.filename)
file.save(os.path.join(app.config['UPLOAD_FOLDER'], filename))
print(file)
video = mp.VideoFileClip("audiofiles/" + filename)
# Extract the audio from the video
audio_file = video.audio
audio_file.write_audiofile("geeksforgeeks.wav")
# Initialize recognizer
r = sr.Recognizer()
# Load the audio file
with sr.AudioFile("geeksforgeeks.wav") as source:
data = r.record(source)
# Convert speech to text
text = r.recognize_google(data)
# Print the text
print("\nThe resultant text from video is: \n")
print(text)
sum = summarize_text(text)
return render_template('transcript.html', transcript=sum, original_transcript=text)
if __name__ == '__main__':
app.run()
# @app.route("/hello")
# def hello():
# return "you are now on hello"
# def h1():
# return "<h1>Hello</h1>"