Update app.py
Browse files
app.py
CHANGED
|
@@ -23,19 +23,15 @@ def optimize_dispatch(solar_max, wind_max, grid_max, load):
|
|
| 23 |
res = linprog(c, A_ub=A_ub, b_ub=b_ub, A_eq=A_eq, b_eq=b_eq, bounds=bounds, method='highs')
|
| 24 |
|
| 25 |
if res.success:
|
| 26 |
-
solar, wind, grid = res.x
|
| 27 |
-
solar, wind, grid = round(solar, 2), round(wind, 2), round(grid, 2)
|
| 28 |
dispatch = {"Solar Power": solar, "Wind Power": wind, "Grid Power": grid}
|
| 29 |
|
| 30 |
-
|
| 31 |
-
plt.figure(figsize=(6,4))
|
| 32 |
plt.bar(dispatch.keys(), dispatch.values(), color=['orange', 'green', 'blue'])
|
| 33 |
plt.title("Optimized Power Dispatch (MW)")
|
| 34 |
plt.ylabel("Power (MW)")
|
| 35 |
-
plt.ylim(0, max(solar_max, wind_max, grid_max, load)*1.1)
|
| 36 |
plt.grid(axis='y')
|
| 37 |
-
|
| 38 |
-
# Save plot to return
|
| 39 |
plt.tight_layout()
|
| 40 |
plt.savefig("dispatch_plot.png")
|
| 41 |
plt.close()
|
|
@@ -44,17 +40,16 @@ def optimize_dispatch(solar_max, wind_max, grid_max, load):
|
|
| 44 |
else:
|
| 45 |
return {"Error": "Optimization failed. Please check inputs."}, None
|
| 46 |
|
| 47 |
-
# Define Gradio interface
|
| 48 |
inputs = [
|
| 49 |
-
gr.
|
| 50 |
-
gr.
|
| 51 |
-
gr.
|
| 52 |
-
gr.
|
| 53 |
]
|
| 54 |
|
| 55 |
outputs = [
|
| 56 |
-
gr.
|
| 57 |
-
gr.
|
| 58 |
]
|
| 59 |
|
| 60 |
demo = gr.Interface(
|
|
|
|
| 23 |
res = linprog(c, A_ub=A_ub, b_ub=b_ub, A_eq=A_eq, b_eq=b_eq, bounds=bounds, method='highs')
|
| 24 |
|
| 25 |
if res.success:
|
| 26 |
+
solar, wind, grid = [round(x, 2) for x in res.x]
|
|
|
|
| 27 |
dispatch = {"Solar Power": solar, "Wind Power": wind, "Grid Power": grid}
|
| 28 |
|
| 29 |
+
plt.figure(figsize=(6, 4))
|
|
|
|
| 30 |
plt.bar(dispatch.keys(), dispatch.values(), color=['orange', 'green', 'blue'])
|
| 31 |
plt.title("Optimized Power Dispatch (MW)")
|
| 32 |
plt.ylabel("Power (MW)")
|
| 33 |
+
plt.ylim(0, max(solar_max, wind_max, grid_max, load) * 1.1)
|
| 34 |
plt.grid(axis='y')
|
|
|
|
|
|
|
| 35 |
plt.tight_layout()
|
| 36 |
plt.savefig("dispatch_plot.png")
|
| 37 |
plt.close()
|
|
|
|
| 40 |
else:
|
| 41 |
return {"Error": "Optimization failed. Please check inputs."}, None
|
| 42 |
|
|
|
|
| 43 |
inputs = [
|
| 44 |
+
gr.Number(label="Solar Max Capacity (MW)", value=50, minimum=0),
|
| 45 |
+
gr.Number(label="Wind Max Capacity (MW)", value=60, minimum=0),
|
| 46 |
+
gr.Number(label="Grid Max Capacity (MW)", value=100, minimum=0),
|
| 47 |
+
gr.Number(label="Load Demand (MW)", value=120, minimum=0),
|
| 48 |
]
|
| 49 |
|
| 50 |
outputs = [
|
| 51 |
+
gr.Label(label="Optimized Dispatch (MW)"),
|
| 52 |
+
gr.Image(type="filepath", label="Dispatch Visualization")
|
| 53 |
]
|
| 54 |
|
| 55 |
demo = gr.Interface(
|