arkacjoy's picture
Upload 7 files
3e89732 verified
Raw
History Blame
967 Bytes
from fastapi import FastAPI, Request, Form, Depends
from fastapi.templating import Jinja2Templates
from fastapi.staticfiles import StaticFiles
import pickle
import numpy as np
# Load the trained model
with open("model.pkl", "rb") as model_file:
model = pickle.load(model_file)
app = FastAPI()
# Setup templates and static files
app.mount("/static", StaticFiles(directory="static"), name="static")
templates = Jinja2Templates(directory="templates")
@app.get("/")
def home(request: Request):
return templates.TemplateResponse("index.html", {"request": request})
@app.post("/predict")
def predict(
request: Request,
x1: float = Form(...),
x2: float = Form(...),
x3: float = Form(...),
x4: float = Form(...),
):
input_features = np.array([[x1, x2, x3, x4]])
prediction = model.predict(input_features)[0] # Get the predicted category
return templates.TemplateResponse("index.html", {"request": request, "result": prediction})