Forums

Chatbot in website doesnt respond

Im new to deploying a website, all the functions in the deployed website already works but the chatbot inside the website doesnt respond to my queries. It works when i run it on my computer/localhost but doesnt when deployed. the chatbot gets responses from the intents.json and i already created the model from the train.py and already put them in their designated directories. the html file already has the needed codes and js script for the rendered chatbot so im not sure why it doesnt work. this is some of the codes in my app.py i think the problem is somewhere here probably

     model = load_model("static/chatbot_model.h5")
    intents = json.loads(open("static/intents.json").read())
    words = pickle.load(open("static/words.pkl", "rb"))
    classes = pickle.load(open("static/classes.pkl", "rb"))

app = Flask(__name__)

@app.route("/")
def home():
    return render_template("Allpage.html")

@app.route("/get", methods=["POST"])
def chatbot_response():
    msg = request.form["msg"]
    if msg.startswith('my name is'):
        name = msg[11:]
        ints = predict_class(msg, model)
        res1 = getResponse(ints, intents)
        res =res1.replace("{n}",name)
    elif msg.startswith('hi my name is'):
        name = msg[14:]
        ints = predict_class(msg, model)
        res1 = getResponse(ints, intents)
        res =res1.replace("{n}",name)
    else:
        ints = predict_class(msg, model)
        res = getResponse(ints, intents)
    return res

def getResponse(ints, intents_json):

    tag = ints[0]["intent"]
    list_of_intents = intents_json["intents"]
    for i in list_of_intents:
        if i["tag"] == tag:
            result = random.choice(i["responses"])
            break
    return result


if __name__ == "__main__":
    app.run()

Any help might do, Thank you :D

What errors do you see in your logs? (link to logs are available on the "Web" page on PythonAnywhere).

Here are the errors:

   2021-05-19 11:11:40,908: OSError: write error
2021-05-19 11:12:22,866: OSError: write error
2021-05-19 12:12:16,372: Error running WSGI application
2021-05-19 12:12:16,373: NameError: name 'app' is not defined
2021-05-19 12:12:16,373:   File "/var/www/seanong2021_pythonanywhere_com_wsgi.py", line 19, in <module>
2021-05-19 12:12:16,373:     from app import app as application  # noqa
2021-05-19 12:12:16,373: 
2021-05-19 12:12:16,373:   File "./app.py", line 15, in <module>
2021-05-19 12:12:16,373:     app.config["DEBUG"] = True
2021-05-19 12:12:16,373: ***************************************************
2021-05-19 12:12:16,373: If you're seeing an import error and don't know why,
2021-05-19 12:12:16,374: we have a dedicated help page to help you debug: 
2021-05-19 12:12:16,374: https://help.pythonanywhere.com/pages/DebuggingImportError/
2021-05-19 12:12:16,374: ***************************************************
2021-05-19 12:42:24,774: Error running WSGI application
2021-05-19 12:42:24,776: ImportError: cannot import name 'app' from 'venv' (/usr/lib/python3.8/venv/__init__.py)
2021-05-19 12:42:24,777:   File "/var/www/seanong2021_pythonanywhere_com_wsgi.py", line 19, in <module>
2021-05-19 12:42:24,777:     from venv import app as application  # noqa
2021-05-19 12:42:24,777: ***************************************************
2021-05-19 12:42:24,777: If you're seeing an import error and don't know why,
2021-05-19 12:42:24,777: we have a dedicated help page to help you debug: 
2021-05-19 12:42:24,777: https://help.pythonanywhere.com/pages/DebuggingImportError/
2021-05-19 12:42:24,777: ***************************************************
2021-05-19 12:42:26,161: Error running WSGI application
2021-05-19 12:42:26,163: ImportError: cannot import name 'app' from 'venv' (/usr/lib/python3.8/venv/__init__.py)
2021-05-19 12:42:26,164:   File "/var/www/seanong2021_pythonanywhere_com_wsgi.py", line 19, in <module>
2021-05-19 12:42:26,164:     from venv import app as application  # noqa
2021-05-19 12:42:26,164: ***************************************************
2021-05-19 12:42:26,164: If you're seeing an import error and don't know why,
2021-05-19 12:42:26,164: we have a dedicated help page to help you debug: 
2021-05-19 12:42:26,164: https://help.pythonanywhere.com/pages/DebuggingImportError/
2021-05-19 12:42:26,164: ***************************************************
2021-05-19 12:42:42,652: Error running WSGI application
2021-05-19 12:42:42,653: ImportError: cannot import name 'app' from 'venv' (/usr/lib/python3.8/venv/__init__.py)
2021-05-19 12:42:42,653:   File "/var/www/seanong2021_pythonanywhere_com_wsgi.py", line 19, in <module>
2021-05-19 12:42:42,653:     from venv import app as application  # noqa
2021-05-19 12:42:42,653: ***************************************************
2021-05-19 12:42:42,653: If you're seeing an import error and don't know why,
2021-05-19 12:42:42,653: we have a dedicated help page to help you debug: 
2021-05-19 12:42:42,654: https://help.pythonanywhere.com/pages/DebuggingImportError/
2021-05-19 12:42:42,654: ***************************************************
2021-05-19 12:42:57,580: OSError: write error
2021-05-19 12:42:57,583: OSError: write error
2021-05-19 12:50:30,175: OSError: write error

here is my wsgi file

import sys
path = '/home/SeanOng2021/Corium/venv'
if path not in sys.path:
    sys.path.append(path)

from app import app as application

Go to the link in the exception message (https://help.pythonanywhere.com/pages/DebuggingImportError/) that describes how Python finds things you import and how you can debug the error.

okie thank you :D

Chatbot still doesnt show any output in my website and i get no errors currently, i feel like something about this code doesnt make my chatbot respond:

@app.route("/get", methods=["POST"])
def chatbot_response():
    msg = request.form["msg"]
    if msg.startswith('my name is'):
        name = msg[11:]
        ints = predict_class(msg, model)
        res1 = getResponse(ints, intents)
        res =res1.replace("{n}",name)
    elif msg.startswith('hi my name is'):
        name = msg[14:]
        ints = predict_class(msg, model)
        res1 = getResponse(ints, intents)
        res =res1.replace("{n}",name)
    else:
        ints = predict_class(msg, model)
        res = getResponse(ints, intents)
    return res

Because when i tried doing this:

@app.route("/get", methods=["POST"])
def chatbot_response():
    msg = request.form["msg"]

    return str(msg)

the chatbot responds an output with the same input that the user types. so i think that the problem might be somewhere with how the chatbot predicts its responses, im currently using keras with tensorflow as a backend

Yes, tensorflow would not work in a web app; we have a help page on that: https://help.pythonanywhere.com/pages/MachineLearningInWebsiteCode/

Thank you

No problem!