-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmipse.py
More file actions
31 lines (27 loc) · 956 Bytes
/
mipse.py
File metadata and controls
31 lines (27 loc) · 956 Bytes
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
from flask import Flask, flash, url_for, render_template, request
from markupsafe import escape
from search_engine import SearchEngine
# export FLASK_APP=mipse
app = Flask('MIPSE')
app.secret_key = 'foobar'
app.config['TEMPLATES_AUTO_RELOAD'] = True
# initiate the search engine class
coco_clip = SearchEngine('coco_dataset')
unsplash_clip = SearchEngine('unsplash_dataset')
search_engines = {
'Coco': coco_clip,
'Unsplash': unsplash_clip
}
@app.route('/', methods=['GET', 'POST'])
def main():
if request.method == 'GET':
return render_template('main_page.html', query="")
elif request.method == 'POST':
query = request.form['query']
search_engine = request.form['dataset']
image_count = int(request.form['image_count'])
return render_template('main_page.html',
query=query,
search_engine=search_engine,
images=search_engines[search_engine].search(query, image_count=image_count),
image_count=image_count)