我想在本地部署一个超级简单的基本应用程序,它使用我之前拟合的ML模型来预测我的测试数据集中的数据.以下是FastAPI模块的格式:
from fastapi import FastAPI
import pickle
import numpy as np
# import pandas as pd
import json
from typing import *
app = FastAPI()
def predict(data: List[float]):
with open("model.pkl", "rb") as f:
model = pickle.load(f)
data = np.array(data).reshape(1, -1)
prediction = model.predict(data)
return prediction
@app.post("/predict")
def predict_route(data: List[float]):
prediction = predict(data)
return {"prediction": prediction}
import requests
f = open('test_data.json',)
data = json.load(f)
response = requests.post("http://localhost:8000/predict", json=data)
print(response.json())
当我try 使用以下工具使其工作时,问题就出现了
uvicorn main:app --reload
个
我从cmd获得以下代码:
requests.exceptions.ConnectionError: HTTPConnectionPool(host='localhost', port=8000): Max retries exceeded with url: /predict (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x000002080F90E870>: Failed to establish a new connection: [WinError 10061] No connection could be made because the target machine actively refused it'))
个
有人能帮助我实现这一点吗?