-
Notifications
You must be signed in to change notification settings - Fork 2
/
app.py
62 lines (45 loc) · 1.58 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
import time
from flask import Flask, render_template, request, g
from src.codevecdb.parse_text import parse_text_and_insert
from src.codevecdb.search_text import search_question
from src.codevecdb.split.split_dispatch import split_file_to_chunks
app = Flask(__name__)
app.config['TEMPLATES_AUTO_RELOAD'] = True
@app.before_request
def before_request():
g.start = time.time()
@app.after_request
def after_request(response):
diff = time.time() - g.start
print(str(diff) + ":" + str(response))
return response
@app.route('/code', methods=['GET', 'POST'])
def post_code():
if request.method == 'POST':
code_str = request.form['code']
results = parse_text_and_insert(code_str)
print("code success")
return render_template('code.html', results=results)
return render_template('code.html')
@app.route('/query', methods=['GET', 'POST'])
def query_code():
if request.method == 'POST':
query = request.form['query']
results = search_question(query)
print("query success")
return render_template('query.html', results=[results])
return render_template('query.html')
@app.route('/upload', methods=['GET', 'POST'])
def upload_file():
if request.method == 'POST':
file = request.files['file']
split_file_to_chunks(file)
print("upload success")
return render_template('upload_file.html')
return render_template('upload_file.html')
@app.route('/')
def hello_world():
results = []
return render_template('index.html', results=results)
if __name__ == '__main__':
app.run()