saba000farahani
commited on
Commit
•
f265442
1
Parent(s):
f40541e
Update app.py
Browse files
app.py
CHANGED
@@ -111,4 +111,89 @@ 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', '
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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 |
+
# Flatten the results into a single list of 13 outputs
|
132 |
+
plot_output = plt
|
133 |
+
contamination_output = [f"{val * 100:.2f}%" for val in contamination_levels[0]]
|
134 |
+
cleaning_time_output = [f"{val:.2f}" for val in cleaning_times]
|
135 |
+
|
136 |
+
return [plot_output] + contamination_output + cleaning_time_output
|
137 |
+
|
138 |
+
except Exception as e:
|
139 |
+
print(f"Error in Gradio interface: {e}")
|
140 |
+
return [plt.figure()] + ["Error"] * 12
|
141 |
+
|
142 |
+
inputs = [
|
143 |
+
gr.Slider(minimum=0, maximum=100, value=50, step=0.05, label="Velocity (mph)"),
|
144 |
+
gr.Slider(minimum=-2, maximum=30, value=0, step=0.5, label="Temperature (°C)"),
|
145 |
+
gr.Slider(minimum=0, maximum=1, value=0, step=0.01, label="Precipitation (inch)"),
|
146 |
+
gr.Slider(minimum=0, maximum=100, value=50, label="Humidity (%)")
|
147 |
+
]
|
148 |
+
|
149 |
+
contamination_outputs = [
|
150 |
+
gr.Textbox(label="Front Left Contamination"),
|
151 |
+
gr.Textbox(label="Front Right Contamination"),
|
152 |
+
gr.Textbox(label="Left Contamination"),
|
153 |
+
gr.Textbox(label="Right Contamination"),
|
154 |
+
gr.Textbox(label="Roof Contamination"),
|
155 |
+
gr.Textbox(label="Rear Contamination")
|
156 |
+
]
|
157 |
+
|
158 |
+
cleaning_time_outputs = [
|
159 |
+
gr.Textbox(label="Front Left Cleaning Time"),
|
160 |
+
gr.Textbox(label="Front Right Cleaning Time"),
|
161 |
+
gr.Textbox(label="Left Cleaning Time"),
|
162 |
+
gr.Textbox(label="Right Cleaning Time"),
|
163 |
+
gr.Textbox(label="Roof Cleaning Time"),
|
164 |
+
gr.Textbox(label="Rear Cleaning Time")
|
165 |
+
]
|
166 |
+
|
167 |
+
with gr.Blocks() as demo:
|
168 |
+
gr.Markdown("<h1 style='text-align: center;'>Environmental Factor-Based Contamination & Cleaning Time Prediction</h1>")
|
169 |
+
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.")
|
170 |
+
|
171 |
+
with gr.Row():
|
172 |
+
with gr.Column():
|
173 |
+
gr.Markdown("### Input Parameters")
|
174 |
+
for inp in inputs:
|
175 |
+
inp.render()
|
176 |
+
|
177 |
+
# Centered image display
|
178 |
+
with gr.Row():
|
179 |
+
with gr.Column(scale=1, min_width=0):
|
180 |
+
gr.Image(image_path) # Ensure the image is centered
|
181 |
+
|
182 |
+
gr.Button(value="Submit", variant="primary").click(
|
183 |
+
fn=predict_and_plot,
|
184 |
+
inputs=inputs,
|
185 |
+
outputs=[gr.Plot(label="Contamination Levels Over Time")] + contamination_outputs + cleaning_time_outputs
|
186 |
+
)
|
187 |
+
gr.Button(value="Clear").click(fn=lambda: None)
|
188 |
+
|
189 |
+
with gr.Column():
|
190 |
+
gr.Markdown("### Contamination Predictions")
|
191 |
+
for out in contamination_outputs:
|
192 |
+
out.render()
|
193 |
+
|
194 |
+
with gr.Column():
|
195 |
+
gr.Markdown("### Cleaning Time Predictions")
|
196 |
+
for out in cleaning_time_outputs:
|
197 |
+
out.render()
|
198 |
+
|
199 |
+
demo.launch()
|