|
from fastapi import FastAPI, HTTPException |
|
from pydantic import BaseModel |
|
import requests |
|
import pandas as pd |
|
|
|
app = FastAPI() |
|
|
|
|
|
class InputData(BaseModel): |
|
dataframe_records: list[dict] |
|
|
|
|
|
@app.post("/predict") |
|
async def make_prediction(input_data: InputData): |
|
|
|
mlflow_url = "http://127.0.0.1:8000/invocations" |
|
headers = {"Content-Type": "application/json"} |
|
|
|
|
|
json_data = { |
|
"dataframe_records": input_data.dataframe_records |
|
} |
|
|
|
try: |
|
|
|
response = requests.post(mlflow_url, headers=headers, json=json_data) |
|
response.raise_for_status() |
|
return response.json() |
|
|
|
except requests.exceptions.HTTPError as err: |
|
raise HTTPException(status_code=response.status_code, detail=str(err)) |
|
except requests.exceptions.RequestException as e: |
|
raise HTTPException(status_code=500, detail=str(e)) |
|
|
|
|
|
|