pgurazada1 commited on
Commit
125e817
·
verified ·
1 Parent(s): 2316d09

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +19 -23
app.py CHANGED
@@ -23,27 +23,13 @@ log_file = Path("logs/") / f"data_{uuid.uuid4()}.json"
23
  log_folder = log_file.parent
24
 
25
  scheduler = CommitScheduler(
26
- repo_id="machine-failure-mlops-logs",
27
  repo_type="dataset",
28
  folder_path=log_folder,
29
  path_in_repo="data",
30
  every=2
31
  )
32
 
33
- # Set up UI components for input and output
34
-
35
- air_temperature_input = gr.Number(label='Air temperature [K]')
36
- process_temperature_input = gr.Number(label='Process temperature [K]')
37
- rotational_speed_input = gr.Number(label='Rotational speed [rpm]')
38
- torque_input = gr.Number(label='Torque [Nm]')
39
- tool_wear_input = gr.Number(label='Tool wear [min]')
40
- type_input = gr.Dropdown(
41
- ['L', 'M', 'H'],
42
- label='Type'
43
- )
44
-
45
- model_output = gr.Label(label="Machine Failure Expected?")
46
-
47
  # Define the predict function that runs when 'Submit' is clicked or when a API request is made
48
  def predict_machine_failure(air_temperature, process_temperature, rotational_speed, torque, tool_wear, type):
49
  sample = {
@@ -54,13 +40,9 @@ def predict_machine_failure(air_temperature, process_temperature, rotational_spe
54
  'Tool wear [min]': tool_wear,
55
  'Type': type
56
  }
57
- data_point = pd.DataFrame([sample])
58
- prediction = machine_failure_predictor.predict(data_point).tolist()[0]
59
 
60
- if prediction == 1:
61
- prediction_label = 'yes'
62
- else:
63
- prediction_label = 'no'
64
 
65
  with scheduler.lock:
66
  with log_file.open("a") as f:
@@ -72,12 +54,26 @@ def predict_machine_failure(air_temperature, process_temperature, rotational_spe
72
  'Torque [Nm]': torque,
73
  'Tool wear [min]': tool_wear,
74
  'Type': type,
75
- 'prediction': prediction_label
76
  }
77
  ))
78
  f.write("\n")
79
 
80
- return prediction_label
 
 
 
 
 
 
 
 
 
 
 
 
 
 
81
 
82
  # Create the interface
83
  demo = gr.Interface(
 
23
  log_folder = log_file.parent
24
 
25
  scheduler = CommitScheduler(
26
+ repo_id="machine-failure-logs",
27
  repo_type="dataset",
28
  folder_path=log_folder,
29
  path_in_repo="data",
30
  every=2
31
  )
32
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
33
  # Define the predict function that runs when 'Submit' is clicked or when a API request is made
34
  def predict_machine_failure(air_temperature, process_temperature, rotational_speed, torque, tool_wear, type):
35
  sample = {
 
40
  'Tool wear [min]': tool_wear,
41
  'Type': type
42
  }
 
 
43
 
44
+ data_point = pd.DataFrame([sample])
45
+ prediction = machine_failure_predictor.predict(data_point).tolist()
 
 
46
 
47
  with scheduler.lock:
48
  with log_file.open("a") as f:
 
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
+ # Set up UI components for input and output
65
+
66
+ air_temperature_input = gr.Number(label='Air temperature [K]')
67
+ process_temperature_input = gr.Number(label='Process temperature [K]')
68
+ rotational_speed_input = gr.Number(label='Rotational speed [rpm]')
69
+ torque_input = gr.Number(label='Torque [Nm]')
70
+ tool_wear_input = gr.Number(label='Tool wear [min]')
71
+ type_input = gr.Dropdown(
72
+ ['L', 'M', 'H'],
73
+ label='Type'
74
+ )
75
+
76
+ model_output = gr.Label(label="Machine Failure Expected?")
77
 
78
  # Create the interface
79
  demo = gr.Interface(