hareshchander commited on
Commit
6db32a0
·
verified ·
1 Parent(s): 9559dd1

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -14
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
- # Create bar chart
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.inputs.Number(label="Solar Max Capacity (MW)", default=50, minimum=0),
50
- gr.inputs.Number(label="Wind Max Capacity (MW)", default=60, minimum=0),
51
- gr.inputs.Number(label="Grid Max Capacity (MW)", default=100, minimum=0),
52
- gr.inputs.Number(label="Load Demand (MW)", default=120, minimum=0),
53
  ]
54
 
55
  outputs = [
56
- gr.outputs.Label(label="Optimized Dispatch (MW)"),
57
- gr.outputs.Image(type="filepath", label="Dispatch Visualization")
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(