-
Notifications
You must be signed in to change notification settings - Fork 3
/
app.py
167 lines (136 loc) · 5.77 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
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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
from flask import Flask, render_template, request, url_for, redirect, session
import GoogleNLPAPI as api
import getYoutubeVideoLinks as getYT
import emailer as email
import speech_recognition as sr
from emailAnalysis import send_email
app = Flask(__name__)
app.secret_key = 'thisisasecretkey'
@app.route('/delallsessions')
def delallsessions():
session.pop('transcript', None)
session.pop('summary', None)
session.pop('keywords', None)
session.pop('email_sent', None)
return redirect('/')
@app.route('/', methods=['GET', 'POST'])
def index():
# session.pop('transcript', None)
# session.pop('summary', None)
# session.pop('keywords', None)
return render_template('index.html', session=session)
@app.route('/record')
def record():
return render_template('record.html')
@app.route('/delsession', methods=['GET', 'POST'])
def delscript():
session.pop('transcript', None)
session.pop('summary', None)
session.pop('keywords', None)
return redirect('/convertwav')
@app.route('/textanalysis', methods=['GET', 'POST'])
def textanalysis():
videos = []
# people = []
# places = []
if 'transcript' in session:
if request.method == 'POST':
emailform = request.form
reciever = emailform['email']
subject = emailform['subject']
send_email(f"{subject} - Your AudioLec Lecture", session['transcript'], reciever,
'hackathon2020', '[email protected]', session['videos'], session['keywords'])
keywords = api.sample_analyze_entities(session['transcript'])
session["keywords"] = []
for x in range(0, len(keywords)):
if not keywords[x].isdigit():
session["keywords"].append(keywords[x])
if 'keywords' in session:
for keyword in keywords:
video = getYT.searchVideoForKeyword(keyword)
for indivvideo in video:
# if catergory == "people":
# people.append(f'{indivvideo}')
# elif catergory == "placesOrOrganizations":
# places.append(f'{indivvideo}')
videos.append(f'{indivvideo}')
session['videos'] = videos
length_keywords = len(session['keywords'])
return render_template('textanalysis.html', session=session, length_keywords=length_keywords)
else:
return redirect('/convertwav')
@app.route('/youtubevids')
def youtubevids():
videos = []
# people = []
# places = []
if 'keywords' in session:
# for catergory, keywords in session['keywords'].items():
# for keyword in keywords:
# video = getYT.searchVideoForKeyword(keyword)
# for indivvideo in video:
# # if catergory == "people":
# # people.append(f'{indivvideo}')
# # elif catergory == "placesOrOrganizations":
# # places.append(f'{indivvideo}')
# videos.append(f'{indivvideo}')
for keyword in session['keywords']:
video = getYT.searchVideoForKeyword(keyword);
for singlevid in video:
videos.append(f'{singlevid}')
return render_template('videos.html', videos=videos)
else:
return redirect('/convertwav')
@app.route('/convertwav', methods=['GET', 'POST'])
def convertwav():
transcript = ""
if request.method == "POST":
if "myfiles[]" not in request.files:
return redirect(request.url)
file = request.files["myfiles[]"]
if file.filename == "":
return redirect(request.url)
if file:
# create recognizer object
recognizer = sr.Recognizer()
# split files
# split_wav = SplitWavAudioMubin(f"{os.path.dirname(__file__)}\\audiofiles", file)
# split_wav.multiple_split(min_per_split=1)
# loop through split files
# session["transcript"] = ""
# for wavfile in glob.glob(f"audiofiles/*.wav"):
# audioFile = sr.AudioFile(wavfile)
# with audioFile as source:
# recognizer.adjust_for_ambient_noise(source)
# data = recognizer.record(source)
# transcript = recognizer.recognize_google(data, key=None)
# session["transcript"] += transcript
# filelist = [ f for f in os.listdir(f"audiofiles") if f.endswith(".wav")]
# for indivfile in filelist:
# os.remove(os.path.join(f"audiofiles", indivfile))
# ******************ORIGINAL CODE ****************************
audioFile = sr.AudioFile(file)
with audioFile as source:
recognizer.adjust_for_ambient_noise(source)
data = recognizer.record(source)
transcript = recognizer.recognize_google(data, key=None)
session['transcript'] = transcript
return redirect('/textanalysis')
return render_template('convertwav.html')
@app.route('/contactform', methods=['GET', 'POST'])
def contactform():
session['valid'] = True
contactform = request.form
sender_email = contactform['email']
subject = contactform['subject'] + f" by: {sender_email}"
msg = contactform['message']
if email == "" or subject == "" or msg == "":
session['valid'] = False
else:
email.send_email(subject, msg, '[email protected]',
'hackathon2020', '[email protected]')
session['email_sent'] = True
return redirect('/#footer')
return redirect('/#footer')
if __name__ == '__main__':
app.run(host="localhost", port=5500, debug=True)