File size: 1,721 Bytes
9248464
 
 
 
 
6dd3e58
9248464
 
 
 
 
 
6dd3e58
d044e51
 
 
affac97
9248464
 
 
 
 
 
 
 
 
 
 
 
 
 
14b8a20
6b119e8
6ce768b
 
 
 
 
9248464
 
ef73d9b
11b447b
ef73d9b
 
11b447b
ef73d9b
 
11b447b
ef73d9b
 
11b447b
ef73d9b
11b447b
 
 
 
9248464
 
 
ef73d9b
9248464
589298f
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
68
69
70
71
72
73
74
75
76
import shutil
import glob
import os

import numpy as np
import pandas as pd
from fastapi import FastAPI,UploadFile,File
from pydantic import BaseModel,Field

from app.modelling import train
from app.inference import predict

dataset=None
trained_model=None
encoder=None
transform=None

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(file:UploadFile=File(...)):
    global dataset
    dataset=pd.read_csv(file.file)
    file.file.close()
    return {"filename": file.filename}
    
@app.post("/train/")
def training():
    if dataset is not None:
        results=train(dataset)
        
        global trained_model
        trained_model=results["model"]
        
        global encoder
        encoder=results["encoder"]
        
        global transform
        transform=results["transform"]
        
        return {"Accuracy":results["Accuracy"],
                "F1_Score":results["F1_Score"]}
    else:
        return {"message":"First Upload Dataset"}

@app.post("/predict/")
def prediction(item:Item):
    if trained_model is not None:
        arr=[[item.Torque,item.Hydraulic_Pressure,item.Cutting,item.Coolant_Pressure,item.Spindle_Speed,item.Coolant_Temperature]]
        results=predict(trained_model,encoder,transform,arr)
        return results
    else:
        return {"message":"First Train Model"}