davoodwadi commited on
Commit
1f80c51
·
verified ·
1 Parent(s): 9c22cf9

first upload of the app without the scheduler

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