File size: 1,107 Bytes
f6dc34d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
31f4f78
f6dc34d
 
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, render_template, request, jsonify
# from flask_cors import CORS
from source_data import get_response
from flask_limiter import Limiter
from flask_limiter.util import get_remote_address
from cahtbott import send_message
app = Flask(__name__)
# CORS(app)
limiter = Limiter(app)

# Comment out @app.get and index_get() if you are using CORS(app) for standalone frontend and uncomment all other commented lines
@app.get("/")
@limiter.limit("3/second; 200/minute; 1200/hour")
def index_get():
    return render_template("base.html")

@app.post("/predict")
def predict():
    text = request.get_json().get("message")
    if len(text) > 100:
        message = {"answer": "I'm sorry, your query has too many characters for me to process. If you would like to speak to a live agent, say 'I would like to speak to a live agent'"}
        return jsonify(message)
    response = get_response(text)
    message = {"answer": response}
    return jsonify(message)


if __name__ == "__main__":
    app.run("0.0.0.0",7860)
    # from waitress import serve
    # serve(app, host="0.0.0.0", port=8080)