-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.py
42 lines (36 loc) · 1.16 KB
/
main.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
from datetime import datetime
from flask import Flask, render_template
from flask_socketio import SocketIO, send
from constants import embeddingCollection, questionCollection
from search import ask
from os import getenv
app = Flask(__name__)
app.config['SECRET_KEY'] = getenv("SECRET_KEY") or 'secret!'
socketio = SocketIO(app, async_handlers=True, cors_allowed_origins="*")
@app.route("/")
def main():
return render_template("index.jinja")
@app.route("/about")
def about():
return render_template(
"about.jinja",
last_update=embeddingCollection.created_at
)
@socketio.on("message")
def handle_message(question):
try:
answer = ask(question)
error = False
except Exception as e:
print(e)
answer = "I'm sorry. An internal error occurred and your request could not be processed; by brain seems to be damaged! Please notify [email protected]."
error = True
send(answer)
if questionCollection:
questionCollection.add_doc({
"question": question,
"answer": answer,
"error": error
})
if __name__ == '__main__':
socketio.run(app, debug=True)