我正在尝试在Google Colab上运行一个“本地”Web应用程序,使用FastAPI/Uvicorn,就像我看到的一些Flask应用程序示例代码一样,但无法使其正常工作。是否有人能够做到这一点?感谢。
已成功安装FastAPI和Uvicorn
!pip install FastAPI -q
!pip install uvicorn -q
示例应用
from fastapi import FastAPI
app = FastAPI()
@app.get("/")
async def root():
return {"message": "Hello World"}
尝试运行
#attempt 1
if __name__ == "__main__":
uvicorn.run("/content/fastapi_002:app", host="127.0.0.1", port=5000, log_level="info")
#attempt 2
#uvicorn main:app --reload
!uvicorn "/content/fastapi_001.ipynb:app" --reload