File size: 1,602 Bytes
9248464 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
import shutil
import glob
import os
import numpy as np
from fastapi import FastAPI,UploadFile,File
from pydantic import BaseModel,Field
from app.modelling import train
from app.inference import predict
class Item(BaseModel):
Torque:float=Field(gt=0,default=24.25)
Hydraulic_Pressure:float=Field(gt=0,default=121.86)
Cutting:float=Field(gt=0,default=2.89)
Coolant_Pressure:float=Field(gt=0,default=6.96)
Spindle_Speed:float=Field(gt=0,default=20504.0)
Coolant_Temperature:float=Field(gt=0,default=14.9)
app=FastAPI()
@app.get("/")
def home():
return {"message":"Hello World!"}
@app.post("/upload/")
def upload_csv(uploaded_file:UploadFile=File(...)):
cwd=os.getcwd()
path=os.path.join(cwd,"app","dataset.csv")
with open(path, 'w+b') as file:
shutil.copyfileobj(uploaded_file.file, file)
return {'file': uploaded_file.filename,
'content': uploaded_file.content_type,
'path': path}
@app.post("/train/")
def training():
cwd=os.getcwd()
path=os.path.join(cwd,"app","dataset.csv")
if os.path.exists(path):
results=train(path)
return results
else:
return {"message":"First Upload Dataset"}
@app.post("/predict/")
def prediction(item:Item):
cwd=os.getcwd()
path=os.path.join(cwd,"app","model.pkl")
if os.path.exists(path):
arr=[[item.Torque,item.Hydraulic_Pressure,item.Cutting,item.Coolant_Pressure,item.Spindle_Speed,item.Coolant_Temperature]]
results=predict(arr)
return results
else:
return {"message":"First Train Model"}
|