Skip to content

Commit b18abf5

Browse files
committed
batch_prediction working fine
1 parent f4f0b90 commit b18abf5

File tree

4 files changed

+36
-0
lines changed

4 files changed

+36
-0
lines changed

__pycache__/app.cpython-310.pyc

793 Bytes
Binary file not shown.

app.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,28 @@ async def train_route():
6464
return Response("Training pipeline is successful")
6565
except Exception as e:
6666
raise NetworkSecurityException(e, sys)
67+
68+
@app.post("/predict")
69+
async def predict_route(request: Request, file:UploadFile = File(...)):
70+
try:
71+
df = pd.read_csv(file.file)
72+
preprocessor = load_object("final_model/preprocessor.pkl")
73+
final_model = load_object("final_model/model.pkl")
74+
network_model = NetworkModel(preprocessor = preprocessor, model=final_model)
75+
print(df.iloc[0])
76+
y_pred = network_model.predict(df)
77+
print(y_pred)
78+
df['predicted_column'] = y_pred
79+
print(df['predicted_column'])
80+
81+
82+
os.makedirs('prediction_output',exist_ok=True)
83+
df.to_csv('prediction_output/output.csv')
84+
table_html = df.to_html(classes='table table-striped')
85+
return templates.TemplateResponse("table.html", {"request": request, "table": table_html})
86+
87+
except Exception as e:
88+
raise NetworkSecurityException(e,sys)
6789

6890

6991
if __name__== "__main__":

prediction_output/output.csv

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
,having_IP_Address,URL_Length,Shortining_Service,having_At_Symbol,double_slash_redirecting,Prefix_Suffix,having_Sub_Domain,SSLfinal_State,Domain_registeration_length,Favicon,port,HTTPS_token,Request_URL,URL_of_Anchor,Links_in_tags,SFH,Submitting_to_email,Abnormal_URL,Redirect,on_mouseover,RightClick,popUpWidnow,Iframe,age_of_domain,DNSRecord,web_traffic,Page_Rank,Google_Index,Links_pointing_to_page,Statistical_report,predicted_column
2+
0,1,-1,1,1,1,-1,1,1,1,1,1,-1,-1,1,1,0,1,1,0,1,1,1,1,1,1,-1,-1,1,1,1,1.0
3+
1,-1,-1,-1,1,-1,1,1,1,-1,1,1,-1,1,1,0,1,1,-1,0,1,1,1,1,-1,-1,1,1,-1,1,1,1.0
4+
2,-1,-1,-1,1,-1,-1,0,0,1,1,1,-1,-1,-1,1,-1,1,-1,1,1,1,1,1,1,1,-1,-1,1,0,1,0.0
5+
3,-1,-1,1,1,1,-1,1,1,1,1,1,1,-1,0,1,1,1,1,0,1,1,1,1,1,1,1,-1,1,1,1,1.0
6+
4,1,1,1,1,1,-1,0,-1,-1,1,1,1,1,0,0,1,1,1,0,1,1,1,1,-1,1,1,-1,1,0,1,1.0
7+
5,1,-1,1,1,1,1,0,-1,-1,1,1,1,1,0,0,-1,1,1,0,1,1,1,1,1,1,1,-1,1,0,1,1.0
8+
6,1,1,1,1,1,-1,0,1,-1,-1,1,1,1,0,-1,1,1,1,0,-1,1,-1,1,-1,1,1,-1,1,0,1,1.0
9+
7,1,-1,1,1,1,-1,-1,-1,1,1,1,1,-1,-1,0,-1,1,1,0,1,1,1,1,-1,-1,-1,-1,1,0,1,0.0
10+
8,1,-1,1,-1,1,-1,-1,1,1,-1,-1,1,-1,0,0,0,-1,1,0,-1,1,-1,-1,1,1,1,-1,1,0,1,1.0
11+
9,1,1,1,1,1,-1,0,-1,-1,1,1,1,1,-1,0,1,1,1,0,1,1,1,1,-1,-1,-1,-1,1,0,1,0.0
12+
10,1,-1,1,1,1,-1,-1,1,1,1,1,1,-1,0,-1,-1,1,1,0,1,1,1,1,1,1,1,-1,1,0,1,1.0
13+
11,-1,1,-1,1,1,-1,0,1,-1,1,1,1,1,0,1,-1,1,1,0,1,1,1,1,1,1,1,-1,1,0,1,0.0

requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,5 @@ certifi
1212
pyaml
1313
fastapi
1414
uvicorn
15+
python-multipart
1516
# -e .

0 commit comments

Comments
 (0)