-
Notifications
You must be signed in to change notification settings - Fork 0
/
crystalSearch.py
51 lines (37 loc) · 1.45 KB
/
crystalSearch.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
import os
from crystalServices import get_crystals_by_image
from crystalServices import get_crystals_by_facets
from flask import Flask, render_template
from webforms import SearchForm
app = Flask(__name__)
app.config.from_object('config.DevConfig')
INPUT_IMAGE_DIR = "static/input_images/"
basedir = os.path.abspath(os.path.dirname(__file__))
@app.route('/')
def index():
return render_template('main.html')
# Pass stuff to navbar
@app.context_processor
def base():
form = SearchForm()
return dict(form=form)
# create search function
@app.route('/search', methods=["POST"])
async def search():
form = SearchForm()
search_image = form.search_image.data
search_image_file = search_image.filename
# save locally
search_image.save(os.path.join(basedir, INPUT_IMAGE_DIR, search_image_file))
# execute vector search in Astra DB
image_results = await get_crystals_by_image(search_image_file)
return render_template("search.html", data=image_results, search_image_file=search_image_file)
# create faceting function (left nav drop-downs)
@app.route('/facet', methods=["POST"])
async def facet():
form = SearchForm()
chakra = form.chakra_select.data
birth_month = form.birth_month_select.data
zodiac_sign = form.zodiac_select.data
data_results = await get_crystals_by_facets(chakra, birth_month, zodiac_sign)
return render_template("facet.html", data=data_results, chakra=chakra, birth_month=birth_month, zodiac_sign=zodiac_sign)