Spaces:
Sleeping
Sleeping
Using the Scheduler
Browse filesUncommenting the scheduler code in app.py
app.py
CHANGED
|
@@ -24,14 +24,14 @@ log_folder = log_file.parent
|
|
| 24 |
hf_token = os.environ.get('HF_TOKEN')
|
| 25 |
print(hf_token)
|
| 26 |
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
|
| 36 |
machine_failure_predictor = joblib.load('model_mf.joblib')
|
| 37 |
|
|
@@ -59,21 +59,21 @@ def predict_machine_failure(air_temperature, process_temperature, rotational_spe
|
|
| 59 |
data_point = pd.DataFrame([sample])
|
| 60 |
prediction = machine_failure_predictor.predict(data_point).tolist()
|
| 61 |
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
|
| 72 |
-
|
| 73 |
-
|
| 74 |
-
|
| 75 |
-
|
| 76 |
-
|
| 77 |
|
| 78 |
return prediction[0]
|
| 79 |
|
|
|
|
| 24 |
hf_token = os.environ.get('HF_TOKEN')
|
| 25 |
print(hf_token)
|
| 26 |
|
| 27 |
+
Scheduler will log every 2 API calls:
|
| 28 |
+
scheduler = CommitScheduler(
|
| 29 |
+
repo_id="machine-failure-logs",
|
| 30 |
+
repo_type="dataset",
|
| 31 |
+
folder_path=log_folder,
|
| 32 |
+
path_in_repo="data",
|
| 33 |
+
every=2
|
| 34 |
+
)
|
| 35 |
|
| 36 |
machine_failure_predictor = joblib.load('model_mf.joblib')
|
| 37 |
|
|
|
|
| 59 |
data_point = pd.DataFrame([sample])
|
| 60 |
prediction = machine_failure_predictor.predict(data_point).tolist()
|
| 61 |
|
| 62 |
+
Each time we get a prediction we will determine if we should log it to a hugging_face dataset according to the schedule definition outside this function
|
| 63 |
+
with scheduler.lock:
|
| 64 |
+
with log_file.open("a") as f:
|
| 65 |
+
f.write(json.dumps(
|
| 66 |
+
{
|
| 67 |
+
'Air temperature [K]': air_temperature,
|
| 68 |
+
'Process temperature [K]': process_temperature,
|
| 69 |
+
'Rotational speed [rpm]': rotational_speed,
|
| 70 |
+
'Torque [Nm]': torque,
|
| 71 |
+
'Tool wear [min]': tool_wear,
|
| 72 |
+
'Type': type,
|
| 73 |
+
'prediction': prediction[0]
|
| 74 |
+
}
|
| 75 |
+
))
|
| 76 |
+
f.write("\n")
|
| 77 |
|
| 78 |
return prediction[0]
|
| 79 |
|