| from fastapi import FastAPI |
| from pydantic import BaseModel |
| from model.inference import inference |
| from db_utils import init_db, insert_prediction,get_latest_prediction,get_all_predictions |
|
|
| app = FastAPI() |
| init_db() |
|
|
| class InputData(BaseModel): |
| input: list |
|
|
| @app.post("/predict") |
| async def predict(data: InputData): |
| input_data = data.input |
| if not input_data: |
| return {"error": "No input data provided"} |
| result = inference(input_data) |
| insert_prediction(input_data, result) |
| return { |
| "message": "Prediction successful", |
| } |
|
|
|
|
| @app.get("/get_predict") |
| async def get_predict(): |
| return get_latest_prediction() |
|
|
| @app.get("/get_all_predictions") |
| async def get_all(): |
| return get_all_predictions() |
|
|
| @app.get("/") |
| async def done(): |
| return "It is Work" |