[Python] invalid command name 'main:app' when I execute "uvicorn main:app --reload"

Discussão em 'Python' iniciado por Stack, Novembro 29, 2024.

  1. Stack

    Stack Membro Participativo

    Good afternoon! When I try to execute the command uvicorn main:app --reloadfor start my local server, the VSCode terminal throws the error invalid command name 'main:app'. The code below imports a variable from the pipeline of the generative AI model using FastAPI to estabilish a route for the generated responses. I guess the trick is in the "main" method that imports uvicorn library and use it to run the app, apparently the code is right but maybe I missed something.

    #main.py
    from fastapi import FastAPI
    import sys
    import os

    # Adds the root directory to sys.path
    sys.path.append(os.path.dirname(os.path.abspath(__file__)))

    from src.inference.pipeline import generate_response
    app = FastAPI()

    @app.post("/predict")
    def predict(input_text: str):
    response = generate_response(input_text)
    return {"response": response}

    if __name__ == "__main__":
    import uvicorn
    uvicorn.run(app, host="0.0.0.0", port=8000, reload=True)

    Continue reading...

Compartilhe esta Página