Forums

1st flask app on this hosting service

hello,

A usual flask app has the the following structure: {backend}: app.py --> for the flask controller

{front end}: templates --> directory for the front end /index.html -> front end data display etc.

How do we retrofit the above structure to pythonanwhere?

Thanks.

Did you try to use this structure and got any errors?

Yes.

Now, the flask_app returned "Error: 'NoneType' object has no attribute 'generate_response' "

'generate_response' is a function from a class in a separate python script, it calls OpenAI's gpt-4 model API.

What's the culprit?

Thanks.

What is the line of code that gave that error? And how was the object that you were trying to call the generate_response method on created?

[formatted by admin]

async def demo():
    chatbot = await init_chatbot()
    print("Ask me anything about 'The Art of War' book (type 'exit' to quit)")

    while True:
        query = input("\nQuestion: ").strip()
        if query.lower() == 'exit':
            break

        response = await chatbot.generate_response(query)
        print(f"Response: {response}")


if __name__ == "__main__":
    import asyncio
    asyncio.run(demo())

the "init_chatbot()" function creates an instance of the class (which is a separate python script).

Apart from any possible issues related to your script, async code is not going to work in our default web apps. You could try either rewritting your app to use synchronuous calls, all try our beta ASGI apps, see here.

Ok, removed asynio and associated code, console did not indicate any error, however, the web interface generated an error, "Something went wrong :-("

at the bottom of the class script, I have the following code:

if name == "main":

run(demo())

problematic with pythonanywhere platform?

typing (libary) is supported but why

"from typing import List, Dict, Union" is flagged?

console: the application is now working.

but the web interface still gave me the dreadful "Something went wrong :-("

Never mind. I've resolved it. The flask app is now working. Thanks alot.

I'm glad it works