diff --git a/app.py b/app.py index 902016f30d12dac4e6f6108f94b0f3ffa328eb4a..5ea2517e54e0d6d07350233148f8de898a09cb35 100644 --- a/app.py +++ b/app.py @@ -1,5 +1,7 @@ from flask import Flask from flask_socketio import SocketIO, send +from database import QAPair +from difflib import get_close_matches import time import threading @@ -9,10 +11,19 @@ socketio = SocketIO(app, cors_allowed_origins='*') waiting_time = 10 last_msg = time.time() + 12 +question = QAPair.query.with_entities(QAPair.question).all() +questions = [a.question for a in question] @socketio.on('message') def handleMessage(msg): - send("message received : " + msg, broadcast=False) #will be replaced with QA matching function + + q = get_close_matches(msg, questions) + # send(q, broadcast=False) + if q: + ans = QAPair.query.filter_by(question = q[0]).first().answer + send(ans, broadcast=False) + else: + send("sorry, I don't understand the question", broadcast = False) global last_msg last_msg = time.time() diff --git a/front.html b/front.html index 71ae430adac10c106f381544f4bb058b70263c4c..8ef555699fdad63c2d4a222b7cb9bd5f29fa6ca9 100644 --- a/front.html +++ b/front.html @@ -9,10 +9,6 @@ $(document).ready(function() { var socket = io.connect('http://127.0.0.1:5000'); - socket.on('connect', function() { - socket.send('connected'); - }); - socket.on('message', function(msg) { $("#messages").append('<li>'+msg+'</li>') }); diff --git a/qa.sqlite3 b/qa.sqlite3 index 204e6af6d43c0ee809826f3dd19338a3caf3b550..3cd0e5c6fe5105c9d0d7d0c65082ff381a334774 100644 Binary files a/qa.sqlite3 and b/qa.sqlite3 differ