savi-cyber commited on
Commit
ce60c4b
·
verified ·
1 Parent(s): 2f7e6e8

Delete app.py

Browse files
Files changed (1) hide show
  1. app.py +0 -75
app.py DELETED
@@ -1,75 +0,0 @@
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
- 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, torque_input, tool_wear_input, type_input],
67
- outputs=model_output,
68
- title="Machine Failure Predictor",
69
- description="This API allows you to predict the machine failure status of an equipment",
70
- allow_flagging="auto",
71
- concurrency_limit=8
72
- )
73
-
74
- demo.queue()
75
- demo.launch(share=False)