Upload app.py
Browse files
app.py
CHANGED
@@ -1,121 +1,78 @@
|
|
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 |
-
log_file = Path("logs/") / f"data_{uuid.uuid4()}.json"
|
13 |
-
log_folder = log_file.parent
|
14 |
-
|
15 |
-
scheduler = CommitScheduler(
|
16 |
-
repo_id="
|
17 |
-
repo_type="dataset",
|
18 |
-
folder_path=log_folder,
|
19 |
-
path_in_repo="data",
|
20 |
-
every=2
|
21 |
-
)
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
'PC Contact Freq': pc_contact_freq,
|
79 |
-
'Job': job,
|
80 |
-
'Marital Status': marital_status,
|
81 |
-
'Education': education,
|
82 |
-
'Defaulter': defaulter,
|
83 |
-
'Home Loan': home_loan,
|
84 |
-
'Personal Loan': personal_loan,
|
85 |
-
'Communication Type': communication_type,
|
86 |
-
'Last Month Contacted': last_contacted,
|
87 |
-
'Day of Week': day_of_week,
|
88 |
-
'PC Outcome': pc_outcome,
|
89 |
-
'prediction': prediction[0]
|
90 |
-
}
|
91 |
-
))
|
92 |
-
f.write("\n")
|
93 |
-
|
94 |
-
return prediction[0]
|
95 |
-
|
96 |
-
demo = gr.Interface(
|
97 |
-
fn=predict_term_deposit,
|
98 |
-
inputs=[age_input,
|
99 |
-
duration_input,
|
100 |
-
cc_contact_freq_input,
|
101 |
-
days_since_pc_input,
|
102 |
-
pc_contact_freq_input,
|
103 |
-
job_input,
|
104 |
-
marital_input,
|
105 |
-
education_input,
|
106 |
-
defaulter_input,
|
107 |
-
home_loan_input,
|
108 |
-
personal_loan_input,
|
109 |
-
communication_type_input,
|
110 |
-
last_contacted_input,
|
111 |
-
day_of_week_input,
|
112 |
-
pc_outcome_input],
|
113 |
-
outputs=model_output,
|
114 |
-
title="Term Deposit Prediction",
|
115 |
-
description="This API allows you to predict the person who are going to likely subscribe the term deposit",
|
116 |
-
allow_flagging="auto",
|
117 |
-
concurrency_limit=8
|
118 |
-
)
|
119 |
-
|
120 |
-
demo.queue()
|
121 |
demo.launch(share=False)
|
|
|
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 |
+
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 |
+
|
23 |
+
machine_failure_predictor = joblib.load('model.joblib')
|
24 |
+
|
25 |
+
air_temperature_input = gr.Number(label='Air temperature [K]')
|
26 |
+
process_temperature_input = gr.Number(label='Process temperature [K]')
|
27 |
+
rotational_speed_input = gr.Number(label='Rotational speed [rpm]')
|
28 |
+
torque_input = gr.Number(label='Torque [Nm]')
|
29 |
+
tool_wear_input = gr.Number(label='Tool wear [min]')
|
30 |
+
type_input = gr.Dropdown(
|
31 |
+
['L', 'M', 'H'],
|
32 |
+
label='Type'
|
33 |
+
)
|
34 |
+
|
35 |
+
model_output = gr.Label(label="Machine failure")
|
36 |
+
|
37 |
+
def predict_machine_failure(air_temperature, process_temperature, rotational_speed, torque, tool_wear, type):
|
38 |
+
sample = {
|
39 |
+
'Air temperature [K]': air_temperature,
|
40 |
+
'Process temperature [K]': process_temperature,
|
41 |
+
'Rotational speed [rpm]': rotational_speed,
|
42 |
+
'Torque [Nm]': torque,
|
43 |
+
'Tool wear [min]': tool_wear,
|
44 |
+
'Type': type
|
45 |
+
}
|
46 |
+
data_point = pd.DataFrame([sample])
|
47 |
+
prediction = machine_failure_predictor.predict(data_point).tolist()
|
48 |
+
|
49 |
+
with scheduler.lock:
|
50 |
+
with log_file.open("a") as f:
|
51 |
+
f.write(json.dumps(
|
52 |
+
{
|
53 |
+
'Air temperature [K]': air_temperature,
|
54 |
+
'Process temperature [K]': process_temperature,
|
55 |
+
'Rotational speed [rpm]': rotational_speed,
|
56 |
+
'Torque [Nm]': torque,
|
57 |
+
'Tool wear [min]': tool_wear,
|
58 |
+
'Type': type,
|
59 |
+
'prediction': prediction[0]
|
60 |
+
}
|
61 |
+
))
|
62 |
+
f.write("\n")
|
63 |
+
|
64 |
+
return prediction[0]
|
65 |
+
|
66 |
+
demo = gr.Interface(
|
67 |
+
fn=predict_machine_failure,
|
68 |
+
inputs=[air_temperature_input, process_temperature_input, rotational_speed_input,
|
69 |
+
torque_input, tool_wear_input, type_input],
|
70 |
+
outputs=model_output,
|
71 |
+
title="Machine Failure Predictor",
|
72 |
+
description="This API allows you to predict the machine failure status of an equipment",
|
73 |
+
allow_flagging="auto",
|
74 |
+
concurrency_limit=8
|
75 |
+
)
|
76 |
+
|
77 |
+
demo.queue()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
78 |
demo.launch(share=False)
|