Update app.py
Browse files
app.py
CHANGED
@@ -1,5 +1,3 @@
|
|
1 |
-
# Import the libraries
|
2 |
-
|
3 |
import os
|
4 |
import uuid
|
5 |
import joblib
|
@@ -17,22 +15,22 @@ from pathlib import Path
|
|
17 |
|
18 |
os.system("python train.py")
|
19 |
|
20 |
-
# Load the freshly trained model from disk
|
21 |
|
22 |
insurance_charge_predictor = joblib.load('model.joblib')
|
23 |
|
24 |
-
# Prepare the logging functionality
|
25 |
|
26 |
-
log_file = Path("logs/") / f"data_{uuid.uuid4()}.json"
|
27 |
-
log_folder = log_file.parent
|
28 |
|
29 |
-
scheduler = CommitScheduler(
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
)
|
36 |
|
37 |
# Define the predict function that runs when 'Submit' is clicked or when a API request is made
|
38 |
def predict_insurance_charge(age, bmi, children,sex, smoker, region):
|
@@ -52,20 +50,20 @@ def predict_insurance_charge(age, bmi, children,sex, smoker, region):
|
|
52 |
# While writing to the log file, ensure that the commit scheduler is locked to avoid parallel
|
53 |
# access
|
54 |
|
55 |
-
with scheduler.lock:
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
|
70 |
return round(prediction[0],2)
|
71 |
|
|
|
|
|
|
|
1 |
import os
|
2 |
import uuid
|
3 |
import joblib
|
|
|
15 |
|
16 |
os.system("python train.py")
|
17 |
|
18 |
+
# # Load the freshly trained model from disk
|
19 |
|
20 |
insurance_charge_predictor = joblib.load('model.joblib')
|
21 |
|
22 |
+
# # Prepare the logging functionality
|
23 |
|
24 |
+
# log_file = Path("logs/") / f"data_{uuid.uuid4()}.json"
|
25 |
+
# log_folder = log_file.parent
|
26 |
|
27 |
+
# scheduler = CommitScheduler(
|
28 |
+
# repo_id="insurance-charge-logs",
|
29 |
+
# repo_type="dataset",
|
30 |
+
# folder_path=log_folder,
|
31 |
+
# path_in_repo="data",
|
32 |
+
# every=2
|
33 |
+
# )
|
34 |
|
35 |
# Define the predict function that runs when 'Submit' is clicked or when a API request is made
|
36 |
def predict_insurance_charge(age, bmi, children,sex, smoker, region):
|
|
|
50 |
# While writing to the log file, ensure that the commit scheduler is locked to avoid parallel
|
51 |
# access
|
52 |
|
53 |
+
# with scheduler.lock:
|
54 |
+
# with log_file.open("a") as f:
|
55 |
+
# f.write(json.dumps(
|
56 |
+
# {
|
57 |
+
# 'age': age,
|
58 |
+
# 'bmi': bmi,
|
59 |
+
# 'children': children,
|
60 |
+
# 'sex': sex,
|
61 |
+
# 'smoker': smoker,
|
62 |
+
# 'region': region,
|
63 |
+
# 'prediction': prediction[0]
|
64 |
+
# }
|
65 |
+
# ))
|
66 |
+
# f.write("\n")
|
67 |
|
68 |
return round(prediction[0],2)
|
69 |
|