-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathapp.py
56 lines (41 loc) · 1.36 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
"""
Flask server to run Scoper with a GUI
"""
from flask import Flask, render_template, request
import nltk
from scoper import Scoper
nltk.download("brown")
APP = Flask(__name__)
print("Please wait loading instance.....")
FINDER = Scoper()
@APP.route("/", methods=["GET", "POST"])
def index():
"""
Home page of Scoper.
"""
if request.method == "POST":
youtube_link = request.form["youtube_link"]
algorithm = request.form["algorithm"]
limit = request.form["limit"]
query = request.form["query"]
print(query)
# check if the values are present
if not (youtube_link and algorithm and limit):
return render_template(
"index.html", error="please enter proper values in the form", empty=True
)
# get the query results
results = FINDER.main(
youtube_link,
query=query,
limit=int(limit),
languages=["en"],
mode=algorithm,
)
# converting results from [('apple watch.', '29m 56s')] to [['apple watch.', '29m56s']]
results = [[x[0], x[1].replace(" ", "")] for x in results]
print(results)
return render_template("index.html", videolink=youtube_link, results=results)
return render_template("index.html", empty=True)
if __name__ == "__main__":
APP.run()