Spaces:
Sleeping
Sleeping
Update main.py
Browse files
main.py
CHANGED
@@ -4,7 +4,7 @@ from fastapi.middleware.cors import CORSMiddleware
|
|
4 |
import requests
|
5 |
import pandas as pd
|
6 |
import json
|
7 |
-
import httpx
|
8 |
import pandas as pd
|
9 |
from sklearn.model_selection import train_test_split, GridSearchCV
|
10 |
from sklearn.preprocessing import LabelEncoder
|
@@ -26,9 +26,8 @@ app.add_middleware(
|
|
26 |
|
27 |
|
28 |
|
29 |
-
def train_the_model(data
|
30 |
-
|
31 |
-
|
32 |
new_data = data
|
33 |
encoders = load('encoders.joblib')
|
34 |
xgb_model = load('xgb_model.joblib')
|
@@ -59,7 +58,7 @@ def train_the_model(data,page):
|
|
59 |
print("Accuracy:", accuracy)
|
60 |
print("Classification Report:\n", classification_report(y_test, y_pred))
|
61 |
|
62 |
-
|
63 |
data = data
|
64 |
|
65 |
# Select columns
|
@@ -165,11 +164,12 @@ async def your_continuous_function(page: int,paginate: int,Tenant: str):
|
|
165 |
print("data collected from page : "+str(page))
|
166 |
#data.to_csv("new.csv")
|
167 |
|
168 |
-
train_the_model(data
|
169 |
|
170 |
return "model trained with page number: "+str(page)+" data count :"+str(data_count)
|
171 |
|
172 |
-
@app.get("/
|
173 |
-
async def
|
174 |
-
|
175 |
-
|
|
|
|
4 |
import requests
|
5 |
import pandas as pd
|
6 |
import json
|
7 |
+
import httpx,os
|
8 |
import pandas as pd
|
9 |
from sklearn.model_selection import train_test_split, GridSearchCV
|
10 |
from sklearn.preprocessing import LabelEncoder
|
|
|
26 |
|
27 |
|
28 |
|
29 |
+
def train_the_model(data):
|
30 |
+
try:
|
|
|
31 |
new_data = data
|
32 |
encoders = load('encoders.joblib')
|
33 |
xgb_model = load('xgb_model.joblib')
|
|
|
58 |
print("Accuracy:", accuracy)
|
59 |
print("Classification Report:\n", classification_report(y_test, y_pred))
|
60 |
|
61 |
+
except:
|
62 |
data = data
|
63 |
|
64 |
# Select columns
|
|
|
164 |
print("data collected from page : "+str(page))
|
165 |
#data.to_csv("new.csv")
|
166 |
|
167 |
+
train_the_model(data)
|
168 |
|
169 |
return "model trained with page number: "+str(page)+" data count :"+str(data_count)
|
170 |
|
171 |
+
@app.get("/get_latest_model_updated_time")
|
172 |
+
async def model_updated_time():
|
173 |
+
m_time_encoder = os.path.getmtime('encoders.joblib')
|
174 |
+
m_time_model = os.path.getmtime('xgb_model.joblib')
|
175 |
+
return {"base model created time ":m_time_encoder,"last model updated time":m_time_model}
|