Spaces:
Runtime error
Runtime error
rickyt
commited on
Commit
·
d3d43d1
1
Parent(s):
a592f47
add graph
Browse files
app.py
CHANGED
|
@@ -85,11 +85,14 @@ def optimize_dynamic(
|
|
| 85 |
result_text += f"\n\n⚡️ Predicted Fuel Rate: {result.fun:.2f} L/cycle"
|
| 86 |
|
| 87 |
# Sensitivity analysis for Engine Speed
|
| 88 |
-
sensitivity_lines = ["\n📊 Suggested RPM vs. Fuel Rate:"]
|
| 89 |
start_rpm = int(round(final_input['Eng_Speed_Ave'] / 50.0) * 50)
|
| 90 |
end_rpm = min(start_rpm + 300, bounds_dict['Eng_Speed_Ave'][1])
|
| 91 |
start_rpm = max(start_rpm, bounds_dict['Eng_Speed_Ave'][0])
|
| 92 |
|
|
|
|
|
|
|
|
|
|
| 93 |
for rpm in range(start_rpm, end_rpm + 1, 50):
|
| 94 |
temp_input = final_input.copy()
|
| 95 |
temp_input['Eng_Speed_Ave'] = rpm
|
|
@@ -114,10 +117,23 @@ def optimize_dynamic(
|
|
| 114 |
else:
|
| 115 |
fuel_rate = best_model.predict(pd.DataFrame([temp_input]))[0]
|
| 116 |
|
| 117 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 118 |
|
| 119 |
-
|
| 120 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 121 |
|
| 122 |
# Gradio Interface (Interface-style)
|
| 123 |
interface = gr.Interface(
|
|
@@ -136,7 +152,10 @@ interface = gr.Interface(
|
|
| 136 |
gr.Checkbox(label="Fix Loading Stop"),
|
| 137 |
gr.Checkbox(label="Fix Loaded Stop"),
|
| 138 |
],
|
| 139 |
-
|
|
|
|
|
|
|
|
|
|
| 140 |
title="⚙️ Fuel Rate What-If Optimizer",
|
| 141 |
description="Perform global optimization of fuel rate with optional fixed inputs and sensitivity on engine RPM."
|
| 142 |
)
|
|
|
|
| 85 |
result_text += f"\n\n⚡️ Predicted Fuel Rate: {result.fun:.2f} L/cycle"
|
| 86 |
|
| 87 |
# Sensitivity analysis for Engine Speed
|
| 88 |
+
# sensitivity_lines = ["\n📊 Suggested RPM vs. Fuel Rate:"]
|
| 89 |
start_rpm = int(round(final_input['Eng_Speed_Ave'] / 50.0) * 50)
|
| 90 |
end_rpm = min(start_rpm + 300, bounds_dict['Eng_Speed_Ave'][1])
|
| 91 |
start_rpm = max(start_rpm, bounds_dict['Eng_Speed_Ave'][0])
|
| 92 |
|
| 93 |
+
rpm_values = []
|
| 94 |
+
fuel_rates = []
|
| 95 |
+
|
| 96 |
for rpm in range(start_rpm, end_rpm + 1, 50):
|
| 97 |
temp_input = final_input.copy()
|
| 98 |
temp_input['Eng_Speed_Ave'] = rpm
|
|
|
|
| 117 |
else:
|
| 118 |
fuel_rate = best_model.predict(pd.DataFrame([temp_input]))[0]
|
| 119 |
|
| 120 |
+
rpm_values.append(rpm)
|
| 121 |
+
fuel_rates.append(fuel_rate)
|
| 122 |
+
|
| 123 |
+
# Create plot
|
| 124 |
+
plt.figure(figsize=(6, 4))
|
| 125 |
+
plt.plot(rpm_values, fuel_rates, marker='o')
|
| 126 |
+
plt.title("Sensitivity of Fuel Rate to Engine Speed")
|
| 127 |
+
plt.xlabel("Engine Speed (RPM)")
|
| 128 |
+
plt.ylabel("Predicted Fuel Rate (L/cycle)")
|
| 129 |
+
plt.grid(True)
|
| 130 |
|
| 131 |
+
# Save and return plot image
|
| 132 |
+
plot_path = "sensitivity_plot.png"
|
| 133 |
+
plt.savefig(plot_path)
|
| 134 |
+
plt.close()
|
| 135 |
+
|
| 136 |
+
return result_text, plot_path
|
| 137 |
|
| 138 |
# Gradio Interface (Interface-style)
|
| 139 |
interface = gr.Interface(
|
|
|
|
| 152 |
gr.Checkbox(label="Fix Loading Stop"),
|
| 153 |
gr.Checkbox(label="Fix Loaded Stop"),
|
| 154 |
],
|
| 155 |
+
outputs=[
|
| 156 |
+
gr.Textbox(label="Optimization Result"),
|
| 157 |
+
gr.Image(type="filepath", label="Sensitivity Plot")
|
| 158 |
+
],
|
| 159 |
title="⚙️ Fuel Rate What-If Optimizer",
|
| 160 |
description="Perform global optimization of fuel rate with optional fixed inputs and sensitivity on engine RPM."
|
| 161 |
)
|