File size: 1,760 Bytes
9248464
 
 
 
 
6dd3e58
9248464
 
 
 
 
 
6dd3e58
affac97
9248464
 
 
 
 
 
 
 
 
 
 
 
 
 
14b8a20
9248464
 
 
 
 
 
 
 
 
 
14b8a20
 
 
6b119e8
02347de
d575138
02347de
 
9248464
 
 
6dd3e58
affac97
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
77
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

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("/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)
        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"}