savi-cyber commited on
Commit
2b7d89b
·
verified ·
1 Parent(s): a38a5c1

corrected upload of files

Browse files
Files changed (3) hide show
  1. app.py +76 -0
  2. model.joblib +3 -0
  3. requirements.txt +3 -0
app.py ADDED
@@ -0,0 +1,76 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ import uuid
3
+ import joblib
4
+ import jsonI
5
+
6
+ import gradio as gr
7
+ import pandas as pd
8
+
9
+ from huggingface_hub import CommitScheduler
10
+ from pathlib import Path
11
+
12
+ log_file = Path("logs/") / f"data_{uuid.uuid4()}.json"
13
+ log_folder = log_file.parent
14
+
15
+ scheduler = CommitScheduler(
16
+ repo_id="machine-failure-logs",
17
+ repo_type="dataset",
18
+ folder_path=log_folder,
19
+ path_in_repo="data",
20
+ every=2
21
+ )
22
+ machine_failure_predictor = joblib.load('model.joblib')
23
+
24
+ air_temperature_input = gr.Number (label='Air temperature [K]')
25
+ process_temperature_input = gr.Number(label='Process temperature [K]')
26
+ rotational_speed_input = gr.Number(label='Rotational speed [rpm]')
27
+ torque_input = gr.Number(label='Torque [Nm]')
28
+ tool_wear_input = gr.Number(label='Tool wear [min]')
29
+ type_input = gr.Dropdown<
30
+ ['L', 'M', 'H'],
31
+ label='Type'
32
+
33
+ model_output = gr.Label(label="Machine failure")
34
+
35
+ def predict_machine_failure(air_temperature, process_temperature, rotational_speed, torque, tool_wear, type):
36
+ sample = {
37
+ 'Air temperature [K]': air_temperature,
38
+ 'Process temperature [K]': process_temperature,
39
+ 'Rotational speed [rpm]': rotational_speed,
40
+ 'Torque [Nm]': torque,
41
+ 'Tool wear [min]': tool_wear,
42
+ 'Type': type
43
+ }
44
+ data_point = pd.DataFrame([sample])
45
+ prediction = macnine_failure_predictor.predict(data_point.tolist()
46
+
47
+ with scheduler.lock:
48
+ with log_file.open("a") as f:
49
+ f.write(json.dumps(
50
+ {
51
+ 'Air temperature [K]': air_temperature,
52
+ 'Process temperature [K]': process_temperature,
53
+ 'Rotatipnal speed [rpm]': rotational_speed,
54
+ 'Torque [Nm]': torque,
55
+ 'Tool wear [min]': tool_wear,
56
+ 'Type': type,
57
+ 'prediction': prediction[0]
58
+ }
59
+ ))
60
+ f.write("\n")
61
+
62
+ return prediction[0]
63
+
64
+ demo = gr.Interface(
65
+ fn=predict_machine_failure,
66
+ inputs=[air_temperature_input, process_temperature_input, rotational_speed_input,
67
+ torque input, tool wear input, type input],
68
+ outputs=model_output,
69
+ title="Machine Failure Predictor",
70
+ description="This API allows you to predict the machine failure status of an equipment",
71
+ allow_flagging="auto",
72
+ concurrency_limit=8
73
+ )
74
+
75
+ demo.queue()
76
+ demo.launch(share=False)
model.joblib ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:a0db284be28e1303ab3612a3a6e35076ff8e9e32c035dd4e2ffdf9635b940780
3
+ size 3838
requirements.txt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ scikit-learn==1.2.2
2
+ pandas==2.0.3
3
+ numpy==1.25.2