saba000farahani commited on
Commit
c75ca98
ยท
verified ยท
1 Parent(s): 119ca14

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +47 -47
app.py CHANGED
@@ -43,22 +43,22 @@ try:
43
 
44
  # Load the models
45
  loaded_rf_model = load(rf_model_path)
46
- print("๋žœ๋ค ํฌ๋ ˆ์ŠคํŠธ ๋ชจ๋ธ์ด ์„ฑ๊ณต์ ์œผ๋กœ ๋กœ๋“œ๋˜์—ˆ์Šต๋‹ˆ๋‹ค.")
47
  loaded_mlp_model = load_model(mlp_model_path)
48
- print("MLP ๋ชจ๋ธ์ด ์„ฑ๊ณต์ ์œผ๋กœ ๋กœ๋“œ๋˜์—ˆ์Šต๋‹ˆ๋‹ค.")
49
  loaded_meta_model = load(meta_model_path)
50
- print("๋ฉ”ํƒ€ ๋ชจ๋ธ์ด ์„ฑ๊ณต์ ์œผ๋กœ ๋กœ๋“œ๋˜์—ˆ์Šต๋‹ˆ๋‹ค.")
51
  except Exception as e:
52
- print(f"๋ชจ๋ธ ๋˜๋Š” ์Šค์ผ€์ผ๋Ÿฌ ๋กœ๋“œ ์ค‘ ์˜ค๋ฅ˜ ๋ฐœ์ƒ: {e}")
53
 
54
  def predict_and_plot(velocity, temperature, precipitation, humidity):
55
  try:
56
  # Prepare the example data
57
  example_data = pd.DataFrame({
58
- '์†๋„(mph)': [velocity],
59
- '์˜จ๋„(ยฐC)': [temperature],
60
- '๊ฐ•์ˆ˜๋Ÿ‰(inch)': [precipitation],
61
- '์Šต๋„(%)': [humidity]
62
  })
63
 
64
  # Scale the example data
@@ -113,20 +113,20 @@ def predict_and_plot(velocity, temperature, precipitation, humidity):
113
  cleaning_times = calculate_cleaning_time(time_intervals, simulated_contamination_levels)
114
 
115
  # Lidar names
116
- lidar_names = ['์•ž/์™ผ์ชฝ', '์•ž/์˜ค๋ฅธ์ชฝ', '์™ผ์ชฝ', '์˜ค๋ฅธ์ชฝ', '์ง€๋ถ•', '๋’ค']
117
 
118
  # Plot the graph
119
  fig, ax = plt.subplots(figsize=(12, 8))
120
 
121
  for i in range(simulated_contamination_levels.shape[1]):
122
  ax.plot(time_intervals, simulated_contamination_levels[:, i], label=f'{lidar_names[i]}')
123
- ax.axhline(y=0.4, color='r', linestyle='--', label='์˜ค์—ผ ์ž„๊ณ„๊ฐ’' if i == 0 else "")
124
  if i < len(cleaning_times):
125
  ax.scatter(cleaning_times[i], 0.4, color='k') # Mark the cleaning time point
126
 
127
- ax.set_title('๊ฐ LiDAR์— ๋Œ€ํ•œ ์‹œ๊ฐ„ ๊ฒฝ๊ณผ์— ๋”ฐ๋ฅธ ์˜ค์—ผ ์ˆ˜์ค€')
128
- ax.set_xlabel('์‹œ๊ฐ„ (์ดˆ)')
129
- ax.set_ylabel('์˜ค์—ผ ์ˆ˜์ค€')
130
  ax.legend()
131
  ax.grid(True)
132
 
@@ -139,80 +139,80 @@ def predict_and_plot(velocity, temperature, precipitation, humidity):
139
  return [plot_output] + contamination_output + gradients_output + cleaning_time_output
140
 
141
  except Exception as e:
142
- print(f"Gradio ์ธํ„ฐํŽ˜์ด์Šค ์˜ค๋ฅ˜ ๋ฐœ์ƒ: {e}")
143
- return [plt.figure()] + ["์˜ค๋ฅ˜"] * 18
144
 
145
  inputs = [
146
- gr.Slider(minimum=0, maximum=100, value=50, step=0.05, label="์†๋„ (mph)"),
147
- gr.Slider(minimum=-2, maximum=30, value=0, step=0.5, label="์˜จ๋„ (ยฐC)"),
148
- gr.Slider(minimum=0, maximum=1, value=0, step=0.01, label="๊ฐ•์ˆ˜๋Ÿ‰ (inch)"),
149
- gr.Slider(minimum=0, maximum=100, value=50, label="์Šต๋„ (%)")
150
  ]
151
 
152
  contamination_outputs = [
153
- gr.Textbox(label="์•ž ์™ผ์ชฝ ์˜ค์—ผ๋„"),
154
- gr.Textbox(label="์•ž ์˜ค๋ฅธ์ชฝ ์˜ค์—ผ๋„"),
155
- gr.Textbox(label="์™ผ์ชฝ ์˜ค์—ผ๋„"),
156
- gr.Textbox(label="์˜ค๋ฅธ์ชฝ ์˜ค์—ผ๋„"),
157
- gr.Textbox(label="์ง€๋ถ• ์˜ค์—ผ๋„"),
158
- gr.Textbox(label="๋’ค ์˜ค์—ผ๋„")
159
  ]
160
 
161
  gradients_outputs = [
162
- gr.Textbox(label="์•ž ์™ผ์ชฝ ๊ธฐ์šธ๊ธฐ"),
163
- gr.Textbox(label="์•ž ์˜ค๋ฅธ์ชฝ ๊ธฐ์šธ๊ธฐ"),
164
- gr.Textbox(label="์™ผ์ชฝ ๊ธฐ์šธ๊ธฐ"),
165
- gr.Textbox(label="์˜ค๋ฅธ์ชฝ ๊ธฐ์šธ๊ธฐ"),
166
- gr.Textbox(label="์ง€๋ถ• ๊ธฐ์šธ๊ธฐ"),
167
- gr.Textbox(label="๋’ค ๊ธฐ์šธ๊ธฐ")
168
  ]
169
 
170
  cleaning_time_outputs = [
171
- gr.Textbox(label="์•ž ์™ผ์ชฝ ์ฒญ์†Œ ์‹œ๊ฐ„"),
172
- gr.Textbox(label="์•ž ์˜ค๋ฅธ์ชฝ ์ฒญ์†Œ ์‹œ๊ฐ„"),
173
- gr.Textbox(label="์™ผ์ชฝ ์ฒญ์†Œ ์‹œ๊ฐ„"),
174
- gr.Textbox(label="์˜ค๋ฅธ์ชฝ ์ฒญ์†Œ ์‹œ๊ฐ„"),
175
- gr.Textbox(label="์ง€๋ถ• ์ฒญ์†Œ ์‹œ๊ฐ„"),
176
- gr.Textbox(label="๋’ค ์ฒญ์†Œ ์‹œ๊ฐ„")
177
  ]
178
 
179
  with gr.Blocks(css=".column-container {height: 100%; display: flex; flex-direction: column; justify-content: space-between;}") as demo:
180
- gr.Markdown("<h1 style='text-align: center;'>ํ™˜๊ฒฝ ์š”์ธ ๊ธฐ๋ฐ˜ ์˜ค์—ผ๋„, ๊ธฐ์šธ๊ธฐ ๋ฐ ์ฒญ์†Œ ์‹œ๊ฐ„ ์˜ˆ์ธก</h1>")
181
- gr.Markdown("์ด ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜์€ ์†๋„, ์˜จ๋„, ๊ฐ•์ˆ˜๋Ÿ‰ ๋ฐ ์Šต๋„์™€ ๊ฐ™์€ ํ™˜๊ฒฝ ์š”์ธ์„ ๊ธฐ๋ฐ˜์œผ๋กœ ์ž๋™์ฐจ์˜ LiDAR ์‹œ์Šคํ…œ์˜ ๋‹ค์–‘ํ•œ ๋ถ€์œ„์— ๋Œ€ํ•œ ์˜ค์—ผ๋„, ๊ธฐ์šธ๊ธฐ ๋ฐ ์ฒญ์†Œ ์‹œ๊ฐ„์„ ์˜ˆ์ธกํ•ฉ๋‹ˆ๋‹ค.")
182
 
183
  # Top Section: Inputs and Car Image
184
  with gr.Row():
185
  with gr.Column(scale=2, elem_classes="column-container"):
186
- gr.Markdown("### ์ž…๋ ฅ ๋งค๊ฐœ๋ณ€์ˆ˜")
187
  for inp in inputs:
188
  inp.render()
189
- submit_button = gr.Button(value="์ œ์ถœ", variant="primary")
190
- clear_button = gr.Button(value="์ดˆ๊ธฐํ™”")
191
 
192
  with gr.Column(scale=1):
193
- gr.Markdown("### LiDAR ์œ„์น˜")
194
  gr.Image(image_path)
195
 
196
  # Bottom Section: Outputs (Three columns)
197
  with gr.Row():
198
  with gr.Column(scale=2):
199
- gr.Markdown("### ์˜ค์—ผ๋„ ์˜ˆ์ธก")
200
  for out in contamination_outputs:
201
  out.render()
202
 
203
  with gr.Column(scale=2):
204
- gr.Markdown("### ๊ธฐ์šธ๊ธฐ ์˜ˆ์ธก")
205
  for out in gradients_outputs:
206
  out.render()
207
 
208
  with gr.Column(scale=2):
209
- gr.Markdown("### ์ฒญ์†Œ ์‹œ๊ฐ„ ์˜ˆ์ธก")
210
  for out in cleaning_time_outputs:
211
  out.render()
212
 
213
  # Graph below the outputs
214
  with gr.Row():
215
- plot_output = gr.Plot(label="์‹œ๊ฐ„ ๊ฒฝ๊ณผ์— ๋”ฐ๋ฅธ ์˜ค์—ผ๋„")
216
 
217
  submit_button.click(
218
  fn=predict_and_plot,
 
43
 
44
  # Load the models
45
  loaded_rf_model = load(rf_model_path)
46
+ print("Random Forest model loaded successfully.")
47
  loaded_mlp_model = load_model(mlp_model_path)
48
+ print("MLP model loaded successfully.")
49
  loaded_meta_model = load(meta_model_path)
50
+ print("Meta model loaded successfully.")
51
  except Exception as e:
52
+ print(f"Error loading models or scaler: {e}")
53
 
54
  def predict_and_plot(velocity, temperature, precipitation, humidity):
55
  try:
56
  # Prepare the example data
57
  example_data = pd.DataFrame({
58
+ 'Velocity(mph)': [velocity],
59
+ 'Temperature': [temperature],
60
+ 'Precipitation': [precipitation],
61
+ 'Humidity': [humidity]
62
  })
63
 
64
  # Scale the example data
 
113
  cleaning_times = calculate_cleaning_time(time_intervals, simulated_contamination_levels)
114
 
115
  # Lidar names
116
+ lidar_names = ['F/L', 'F/R', 'Left', 'Right', 'Roof', 'Rear']
117
 
118
  # Plot the graph
119
  fig, ax = plt.subplots(figsize=(12, 8))
120
 
121
  for i in range(simulated_contamination_levels.shape[1]):
122
  ax.plot(time_intervals, simulated_contamination_levels[:, i], label=f'{lidar_names[i]}')
123
+ ax.axhline(y=0.4, color='r', linestyle='--', label='Contamination Threshold' if i == 0 else "")
124
  if i < len(cleaning_times):
125
  ax.scatter(cleaning_times[i], 0.4, color='k') # Mark the cleaning time point
126
 
127
+ ax.set_title('Contamination Levels Over Time for Each Lidar')
128
+ ax.set_xlabel('Time (seconds)')
129
+ ax.set_ylabel('Contamination Level')
130
  ax.legend()
131
  ax.grid(True)
132
 
 
139
  return [plot_output] + contamination_output + gradients_output + cleaning_time_output
140
 
141
  except Exception as e:
142
+ print(f"Error in Gradio interface: {e}")
143
+ return [plt.figure()] + ["Error"] * 18
144
 
145
  inputs = [
146
+ gr.Slider(minimum=0, maximum=100, value=50, step=0.05, label="Velocity (mph)"),
147
+ gr.Slider(minimum=-2, maximum=30, value=0, step=0.5, label="Temperature (ยฐC)"),
148
+ gr.Slider(minimum=0, maximum=1, value=0, step=0.01, label="Precipitation (inch)"),
149
+ gr.Slider(minimum=0, maximum=100, value=50, label="Humidity (%)")
150
  ]
151
 
152
  contamination_outputs = [
153
+ gr.Textbox(label="Front Left Contamination"),
154
+ gr.Textbox(label="Front Right Contamination"),
155
+ gr.Textbox(label="Left Contamination"),
156
+ gr.Textbox(label="Right Contamination"),
157
+ gr.Textbox(label="Roof Contamination"),
158
+ gr.Textbox(label="Rear Contamination")
159
  ]
160
 
161
  gradients_outputs = [
162
+ gr.Textbox(label="Front Left Gradient"),
163
+ gr.Textbox(label="Front Right Gradient"),
164
+ gr.Textbox(label="Left Gradient"),
165
+ gr.Textbox(label="Right Gradient"),
166
+ gr.Textbox(label="Roof Gradient"),
167
+ gr.Textbox(label="Rear Gradient")
168
  ]
169
 
170
  cleaning_time_outputs = [
171
+ gr.Textbox(label="Front Left Cleaning Time"),
172
+ gr.Textbox(label="Front Right Cleaning Time"),
173
+ gr.Textbox(label="Left Cleaning Time"),
174
+ gr.Textbox(label="Right Cleaning Time"),
175
+ gr.Textbox(label="Roof Cleaning Time"),
176
+ gr.Textbox(label="Rear Cleaning Time")
177
  ]
178
 
179
  with gr.Blocks(css=".column-container {height: 100%; display: flex; flex-direction: column; justify-content: space-between;}") as demo:
180
+ gr.Markdown("<h1 style='text-align: center;'>Environmental Factor-Based Contamination, Gradient, & Cleaning Time Prediction</h1>")
181
+ gr.Markdown("This application predicts the contamination levels, gradients, and cleaning times for different parts of a car's LiDAR system based on environmental factors such as velocity, temperature, precipitation, and humidity.")
182
 
183
  # Top Section: Inputs and Car Image
184
  with gr.Row():
185
  with gr.Column(scale=2, elem_classes="column-container"):
186
+ gr.Markdown("### Input Parameters")
187
  for inp in inputs:
188
  inp.render()
189
+ submit_button = gr.Button(value="Submit", variant="primary")
190
+ clear_button = gr.Button(value="Clear")
191
 
192
  with gr.Column(scale=1):
193
+ gr.Markdown("### Location of LiDARs")
194
  gr.Image(image_path)
195
 
196
  # Bottom Section: Outputs (Three columns)
197
  with gr.Row():
198
  with gr.Column(scale=2):
199
+ gr.Markdown("### Contamination Predictions")
200
  for out in contamination_outputs:
201
  out.render()
202
 
203
  with gr.Column(scale=2):
204
+ gr.Markdown("### Gradient Predictions")
205
  for out in gradients_outputs:
206
  out.render()
207
 
208
  with gr.Column(scale=2):
209
+ gr.Markdown("### Cleaning Time Predictions")
210
  for out in cleaning_time_outputs:
211
  out.render()
212
 
213
  # Graph below the outputs
214
  with gr.Row():
215
+ plot_output = gr.Plot(label="Contamination Levels Over Time")
216
 
217
  submit_button.click(
218
  fn=predict_and_plot,