pgurazada1 commited on
Commit
8e5a70e
·
verified ·
1 Parent(s): 9d42502

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +14 -1
app.py CHANGED
@@ -9,6 +9,16 @@ import pandas as pd
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
 
@@ -20,7 +30,7 @@ scheduler = CommitScheduler(
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]')
@@ -34,6 +44,7 @@ type_input = gr.Dropdown(
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,
@@ -63,6 +74,7 @@ def predict_machine_failure(air_temperature, process_temperature, rotational_spe
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,
@@ -74,5 +86,6 @@ demo = gr.Interface(
74
  concurrency_limit=8
75
  )
76
 
 
77
  demo.queue()
78
  demo.launch(share=False)
 
9
  from huggingface_hub import CommitScheduler
10
  from pathlib import Path
11
 
12
+ # Run the training script in the same directory
13
+
14
+ os.system("python train.py")
15
+
16
+ # Load the freshly trained model
17
+
18
+ machine_failure_predictor = joblib.load('model.joblib')
19
+
20
+ # Prepare the logging functionality
21
+
22
  log_file = Path("logs/") / f"data_{uuid.uuid4()}.json"
23
  log_folder = log_file.parent
24
 
 
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]')
 
44
 
45
  model_output = gr.Label(label="Machine failure")
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 = {
50
  'Air temperature [K]': air_temperature,
 
74
 
75
  return prediction[0]
76
 
77
+ # Create the interface
78
  demo = gr.Interface(
79
  fn=predict_machine_failure,
80
  inputs=[air_temperature_input, process_temperature_input, rotational_speed_input,
 
86
  concurrency_limit=8
87
  )
88
 
89
+ # Launch with a load balancer
90
  demo.queue()
91
  demo.launch(share=False)