Update app/main.py
Browse files- app/main.py +6 -5
app/main.py
CHANGED
@@ -14,6 +14,7 @@ dataset=None
|
|
14 |
trained_model=None
|
15 |
encoder=None
|
16 |
transform=None
|
|
|
17 |
|
18 |
class Item(BaseModel):
|
19 |
Torque:float=Field(gt=0,default=24.25)
|
@@ -31,13 +32,15 @@ def home():
|
|
31 |
|
32 |
@app.post("/upload/")
|
33 |
def upload_csv(file:UploadFile=File(...)):
|
|
|
34 |
dataset=pd.read_csv(file.file)
|
35 |
file.file.close()
|
36 |
return {"filename": file.filename}
|
37 |
|
38 |
@app.post("/train/")
|
39 |
def training():
|
40 |
-
if
|
|
|
41 |
results=train(dataset)
|
42 |
trained_model=results["model"]
|
43 |
encoder=results["encoder"]
|
@@ -49,11 +52,9 @@ def training():
|
|
49 |
|
50 |
@app.post("/predict/")
|
51 |
def prediction(item:Item):
|
52 |
-
|
53 |
-
path=os.path.join(cwd,"app","model.pkl")
|
54 |
-
if os.path.exists(path):
|
55 |
arr=[[item.Torque,item.Hydraulic_Pressure,item.Cutting,item.Coolant_Pressure,item.Spindle_Speed,item.Coolant_Temperature]]
|
56 |
-
results=predict(arr)
|
57 |
return results
|
58 |
else:
|
59 |
return {"message":"First Train Model"}
|
|
|
14 |
trained_model=None
|
15 |
encoder=None
|
16 |
transform=None
|
17 |
+
step=0
|
18 |
|
19 |
class Item(BaseModel):
|
20 |
Torque:float=Field(gt=0,default=24.25)
|
|
|
32 |
|
33 |
@app.post("/upload/")
|
34 |
def upload_csv(file:UploadFile=File(...)):
|
35 |
+
step=1
|
36 |
dataset=pd.read_csv(file.file)
|
37 |
file.file.close()
|
38 |
return {"filename": file.filename}
|
39 |
|
40 |
@app.post("/train/")
|
41 |
def training():
|
42 |
+
if step>0:
|
43 |
+
step=2
|
44 |
results=train(dataset)
|
45 |
trained_model=results["model"]
|
46 |
encoder=results["encoder"]
|
|
|
52 |
|
53 |
@app.post("/predict/")
|
54 |
def prediction(item:Item):
|
55 |
+
if step>1:
|
|
|
|
|
56 |
arr=[[item.Torque,item.Hydraulic_Pressure,item.Cutting,item.Coolant_Pressure,item.Spindle_Speed,item.Coolant_Temperature]]
|
57 |
+
results=predict(trained_model,encoder,transform,arr)
|
58 |
return results
|
59 |
else:
|
60 |
return {"message":"First Train Model"}
|