saba000farahani commited on
Commit
f40541e
·
verified ·
1 Parent(s): 1770619

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +1 -82
app.py CHANGED
@@ -111,85 +111,4 @@ def predict_and_plot(velocity, temperature, precipitation, humidity):
111
  cleaning_times = calculate_cleaning_time(time_intervals, simulated_contamination_levels)
112
 
113
  # Lidar names
114
- lidar_names = ['F/L', 'F/R', 'Left', 'Right', 'Roof', 'Rear']
115
-
116
- # Plot the graph
117
- plt.figure(figsize=(12, 8))
118
-
119
- for i in range(simulated_contamination_levels.shape[1]):
120
- plt.plot(time_intervals, simulated_contamination_levels[:, i], label=f'{lidar_names[i]}')
121
- plt.axhline(y=0.4, color='r', linestyle='--', label='Contamination Threshold' if i == 0 else "")
122
- if i < len(cleaning_times):
123
- plt.scatter(cleaning_times[i], 0.4, color='k') # Mark the cleaning time point
124
-
125
- plt.title('Contamination Levels Over Time for Each Lidar')
126
- plt.xlabel('Time (seconds)')
127
- plt.ylabel('Contamination Level')
128
- plt.legend()
129
- plt.grid(True)
130
-
131
- # Return the plot and predictions
132
- return plt, [f"{val * 100:.2f}%" for val in contamination_levels[0]], [f"{val:.2f}" for val in cleaning_times]
133
-
134
- except Exception as e:
135
- print(f"Error in Gradio interface: {e}")
136
- return plt.figure(), ["Error"] * 6, ["Error"] * 6
137
-
138
- inputs = [
139
- gr.Slider(minimum=0, maximum=100, value=50, step=0.05, label="Velocity (mph)"),
140
- gr.Slider(minimum=-2, maximum=30, value=0, step=0.5, label="Temperature (°C)"),
141
- gr.Slider(minimum=0, maximum=1, value=0, step=0.01, label="Precipitation (inch)"),
142
- gr.Slider(minimum=0, maximum=100, value=50, label="Humidity (%)")
143
- ]
144
-
145
- contamination_outputs = [
146
- gr.Textbox(label="Front Left Contamination"),
147
- gr.Textbox(label="Front Right Contamination"),
148
- gr.Textbox(label="Left Contamination"),
149
- gr.Textbox(label="Right Contamination"),
150
- gr.Textbox(label="Roof Contamination"),
151
- gr.Textbox(label="Rear Contamination")
152
- ]
153
-
154
- cleaning_time_outputs = [
155
- gr.Textbox(label="Front Left Cleaning Time"),
156
- gr.Textbox(label="Front Right Cleaning Time"),
157
- gr.Textbox(label="Left Cleaning Time"),
158
- gr.Textbox(label="Right Cleaning Time"),
159
- gr.Textbox(label="Roof Cleaning Time"),
160
- gr.Textbox(label="Rear Cleaning Time")
161
- ]
162
-
163
- with gr.Blocks() as demo:
164
- gr.Markdown("<h1 style='text-align: center;'>Environmental Factor-Based Contamination & Cleaning Time Prediction</h1>")
165
- gr.Markdown("This application predicts the contamination levels, corresponding gradients, and cleaning times for different parts of a car's LiDAR system based on environmental factors such as velocity, temperature, precipitation, and humidity.")
166
-
167
- with gr.Row():
168
- with gr.Column():
169
- gr.Markdown("### Input Parameters")
170
- for inp in inputs:
171
- inp.render()
172
-
173
- # Centered image display
174
- with gr.Row():
175
- with gr.Column(scale=1, min_width=0):
176
- gr.Image(image_path) # Ensure the image is centered
177
-
178
- gr.Button(value="Submit", variant="primary").click(
179
- fn=predict_and_plot,
180
- inputs=inputs,
181
- outputs=[gr.Plot(label="Contamination Levels Over Time")] + contamination_outputs + cleaning_time_outputs
182
- )
183
- gr.Button(value="Clear").click(fn=lambda: None)
184
-
185
- with gr.Column():
186
- gr.Markdown("### Contamination Predictions")
187
- for out in contamination_outputs:
188
- out.render()
189
-
190
- with gr.Column():
191
- gr.Markdown("### Cleaning Time Predictions")
192
- for out in cleaning_time_outputs:
193
- out.render()
194
-
195
- demo.launch()
 
111
  cleaning_times = calculate_cleaning_time(time_intervals, simulated_contamination_levels)
112
 
113
  # Lidar names
114
+ lidar_names = ['F/L', 'F/R', 'Left', '