Update app.py
Browse files
app.py
CHANGED
@@ -21,16 +21,16 @@ insurance_charge_predictor = joblib.load('model.joblib')
|
|
21 |
|
22 |
# # Prepare the logging functionality
|
23 |
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
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,20 +50,20 @@ 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 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
|
68 |
return round(prediction[0],2)
|
69 |
|
|
|
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 |
|