bgamazay commited on
Commit
6bf06e3
·
verified ·
1 Parent(s): 75a68e9

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +73 -42
app.py CHANGED
@@ -13,6 +13,7 @@ st.set_page_config(
13
  # --- Custom CSS ---
14
  st.markdown("""
15
  <style>
 
16
  .metric-card {
17
  background-color: #f0f2f6;
18
  padding: 20px;
@@ -28,12 +29,26 @@ st.markdown("""
28
  color: #ff4b4b;
29
  }
30
  .sub-text {
31
- font-size: 1.6em;
32
  color: #555;
33
  }
34
- .stPlotlyChart {
35
- display: flex;
36
- justify-content: center;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
37
  }
38
  </style>
39
  """, unsafe_allow_html=True)
@@ -48,41 +63,71 @@ st.divider()
48
 
49
  # --- Sidebar Inputs ---
50
  st.sidebar.header("⚙️ Scenario Settings")
 
51
 
52
  # 1. AI Power Demand
 
53
  ai_demand_gw = st.sidebar.number_input(
54
- "AI Power Demand in 2030 (GW)",
55
  value=100,
56
  step=10,
57
- help="Projected total power load required by AI data centers in 2030."
58
  )
 
 
 
 
59
 
60
  # 2. Gas Share
 
61
  gas_share = st.sidebar.slider(
62
- "Natural Gas Proportion (%)",
63
  min_value=0, max_value=100, value=90, step=5,
64
- help="The percentage of AI power demand that will be met specifically by Natural Gas generation (vs. Renewables/Nuclear)."
65
  )
66
-
67
- # 3. Turbine Efficiency (The new logic)
68
- # Range 35% (Aeroderivative) to 60% (H-Class CCGT)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
69
  turbine_eff_percent = st.sidebar.slider(
70
- "Gas Turbine Average Efficiency (%)",
71
  min_value=35, max_value=60, value=45, step=1,
72
- help="Thermal efficiency of the gas fleet. 35-40% = Peakers/Aeroderivative. 50-60% = Modern Combined Cycle (CCGT)."
73
  )
 
 
 
 
 
 
 
 
 
 
 
74
 
75
  # Constants
76
- CAPACITY_FACTOR = 0.90 # Fixed as requested
77
- US_BASELINE_MMT = 6343 # EPA Gross GHG Inventory Proxy
78
- # Base reference: 486 gCO2e/kWh at 60% efficiency
79
- # Constant for Carbon Content of Fuel derived from this: 486 * 0.60 = 291.6
80
  FUEL_CARBON_CONSTANT = 486 * 0.60
81
 
82
  # --- Calculations ---
83
 
84
- # 1. Calculate Emissions Factor based on selected efficiency
85
- # Formula: EF_output = Constant_Fuel_Carbon / Efficiency
86
  if turbine_eff_percent > 0:
87
  calculated_ef = FUEL_CARBON_CONSTANT / (turbine_eff_percent / 100)
88
  else:
@@ -93,42 +138,35 @@ gas_gw_capacity = ai_demand_gw * (gas_share/100)
93
  total_gwh = gas_gw_capacity * CAPACITY_FACTOR * 8760
94
 
95
  # 3. Calculate Emissions (MMT CO2e)
96
- # (GWh * 1,000,000 -> kWh) * (gCO2 / 1,000,000 -> Tonnes) / 1,000,000 -> Million Tonnes
97
- # Simplifies to (GWh * EF) / 1,000,000
98
  ai_emissions_mmt = (total_gwh * calculated_ef) / 1_000_000
99
-
100
  percent_increase = (ai_emissions_mmt / US_BASELINE_MMT) * 100
101
 
102
  # --- Dashboard Layout ---
103
 
104
- # 1. The Big Number (Centered)
105
  c1, c2, c3 = st.columns([1, 2, 1])
106
  with c2:
107
  st.markdown(f"""
108
  <div class="metric-card">
109
- <div class="sub-text">Projected 2030 US Emissions Increase</div>
110
  <div class="big-number">+{percent_increase:.2f}%</div>
111
  <div class="sub-text">({ai_emissions_mmt:.1f} Million tCO2e)</div>
112
- <div style="font-size: 1.1em; color: #888; margin-top: 10px;">
113
- Based on {turbine_eff_percent}% Efficiency & {gas_share}% Gas Share
114
  </div>
115
  </div>
116
  """, unsafe_allow_html=True)
117
 
118
- # 2. Charts (Centered / Full Width)
119
- # Using columns with spacers to center the chart if it feels too wide,
120
- # or just full width for better visibility.
121
  st.subheader("US Emissions Trajectory vs. AI Impact")
122
 
123
- # Data Setup
124
- years = [2020, 2023]
125
- emissions_hist = [6000, 6200]
126
- target_2030 = 7200 * 0.50 # 50% reduction from 2005
127
- bau_2030 = 5800 # Optimistic business-as-usual decline
128
 
129
  fig1 = go.Figure()
130
 
131
- # History Line
132
  fig1.add_trace(go.Scatter(
133
  x=years, y=emissions_hist,
134
  mode='lines+markers',
@@ -136,7 +174,6 @@ fig1.add_trace(go.Scatter(
136
  line=dict(color='gray', width=2)
137
  ))
138
 
139
- # Target Path Line
140
  fig1.add_trace(go.Scatter(
141
  x=[2023, 2030], y=[6200, target_2030],
142
  mode='lines',
@@ -144,7 +181,6 @@ fig1.add_trace(go.Scatter(
144
  line=dict(color='green', dash='dash', width=2)
145
  ))
146
 
147
- # AI Impact Stacked Bar
148
  fig1.add_trace(go.Bar(
149
  x=[2030], y=[bau_2030],
150
  name='2030 Baseline Estimate',
@@ -166,10 +202,8 @@ fig1.update_layout(
166
  hovermode="x unified"
167
  )
168
 
169
- # Centering the chart using container width
170
  st.plotly_chart(fig1, use_container_width=True)
171
 
172
-
173
  st.markdown("---")
174
  with st.expander("📚 Data Sources & Methodology"):
175
  st.markdown(f"""
@@ -178,7 +212,4 @@ with st.expander("📚 Data Sources & Methodology"):
178
  * **Efficiency Logic:** Emissions Factor is calculated dynamically based on the **Electrical Efficiency** slider ({turbine_eff_percent}% currently selected).
179
  * *Formula:* `EF = (Benchmark Carbon Content) / Efficiency %`
180
  * *Benchmark:* Based on standard NREL data for CCGT (486 gCO2e/kWh @ 60% efficiency).
181
- * Lower efficiency (e.g., 35% for Aeroderivative/Peakers) results in higher emissions per kWh.
182
- * **Capacity Factor:** Fixed at **{int(CAPACITY_FACTOR*100)}%** to represent high uptime requirements for AI workloads.
183
- * **Source Data:** Turbine efficiency ranges (35-60%) derived from industrial comparisons of Aeroderivative GTs vs H-Class CCGTs.
184
  """)
 
13
  # --- Custom CSS ---
14
  st.markdown("""
15
  <style>
16
+ /* Main Dashboard Styling */
17
  .metric-card {
18
  background-color: #f0f2f6;
19
  padding: 20px;
 
29
  color: #ff4b4b;
30
  }
31
  .sub-text {
32
+ font-size: 1.2em;
33
  color: #555;
34
  }
35
+
36
+ /* Sidebar Styling Override */
37
+ [data-testid="stSidebar"] {
38
+ font-size: 1.4rem;
39
+ }
40
+ [data-testid="stSidebar"] label {
41
+ font-size: 1.1rem !important;
42
+ font-weight: 500 !important;
43
+ }
44
+ .sidebar-question {
45
+ font-size: 1.15rem;
46
+ font-weight: bold;
47
+ margin-bottom: 5px;
48
+ color: #31333F;
49
+ }
50
+ .spacer {
51
+ margin-bottom: 2rem;
52
  }
53
  </style>
54
  """, unsafe_allow_html=True)
 
63
 
64
  # --- Sidebar Inputs ---
65
  st.sidebar.header("⚙️ Scenario Settings")
66
+ st.sidebar.markdown("---")
67
 
68
  # 1. AI Power Demand
69
+ st.sidebar.markdown('<p class="sidebar-question">1. How much power will AI require in 2030?</p>', unsafe_allow_html=True)
70
  ai_demand_gw = st.sidebar.number_input(
71
+ "Demand (GW)",
72
  value=100,
73
  step=10,
74
+ label_visibility="collapsed" # Hides the default label since we used a custom header
75
  )
76
+ with st.sidebar.expander("ℹ️ More on AI Demand Forecasts"):
77
+ st.write("According to [EpochAI](https://epoch.ai/gradient-updates/is-almost-everyone-wrong-about-americas-ai-power-problem#:~:text=Our%20best%20projections%20suggest%20that%20the%20US%20will%20need%20around%20100%20GW%20of%20power%20by%202030.) the best projections suggest that the US will need ~100 GW of power by 2030.")
78
+
79
+ st.sidebar.markdown('<div class="spacer"></div>', unsafe_allow_html=True)
80
 
81
  # 2. Gas Share
82
+ st.sidebar.markdown('<p class="sidebar-question">2. What proportion of power will be supplied by natural gas?</p>', unsafe_allow_html=True)
83
  gas_share = st.sidebar.slider(
84
+ "Gas Share",
85
  min_value=0, max_value=100, value=90, step=5,
86
+ label_visibility="collapsed"
87
  )
88
+ st.sidebar.caption(f"Selected: **{gas_share}%**")
89
+
90
+ with st.sidebar.expander("ℹ️ More on Energy Mix"):
91
+ st.markdown("""
92
+ **Why Gas?**
93
+ The electric grid in major hubs like Texas is effectively "sold out," with wait times for connection approaching 5 years. To bypass this, AI labs are adopting "Bring Your Own Generation" (BYOG) strategies, primarily using natural gas which can be deployed in months rather than years.
94
+
95
+ **What about Solar?**
96
+ While solar prices have dropped ~88% since 2009, it faces physical limits:
97
+ * **Land Use:** 2 GW of solar requires a land area roughly the size of Manhattan.
98
+ * **Uptime:** Solar requires battery backup for 24/7 reliability, adding complexity for off-grid "island" data centers.
99
+ [Source](https://open.substack.com/pub/semianalysis/p/how-ai-labs-are-solving-the-power)
100
+ """)
101
+
102
+ st.sidebar.markdown('<div class="spacer"></div>', unsafe_allow_html=True)
103
+
104
+ # 3. Turbine Efficiency
105
+ st.sidebar.markdown('<p class="sidebar-question">3. What will the efficiency of the gas turbines be?</p>', unsafe_allow_html=True)
106
  turbine_eff_percent = st.sidebar.slider(
107
+ "Efficiency",
108
  min_value=35, max_value=60, value=45, step=1,
109
+ label_visibility="collapsed"
110
  )
111
+ st.sidebar.caption(f"Selected: **{turbine_eff_percent}%**")
112
+
113
+ with st.sidebar.expander("ℹ️ More on Turbine Tech"):
114
+ st.markdown("""
115
+ **Efficiency varies by speed and scale:**
116
+
117
+ * **Aeroderivative (35-40%):** Modified jet engines (e.g., GE LM2500). They are less efficient but fast to deploy. Companies like xAI use them to bypass grid delays.
118
+ * **Reciprocating Engines (40-50%):** Modular internal combustion engines (e.g., Wärtsilä). They offer higher efficiency than aeroderivatives and handle partial loads well.
119
+ * **Combined Cycle (50-60%):** The gold standard for efficiency, using waste heat to drive a steam turbine. However, they take 36-60 months to build, making them too slow for the current AI race.
120
+ [Source](https://open.substack.com/pub/semianalysis/p/how-ai-labs-are-solving-the-power)
121
+ """)
122
 
123
  # Constants
124
+ CAPACITY_FACTOR = 0.90
125
+ US_BASELINE_MMT = 6343
 
 
126
  FUEL_CARBON_CONSTANT = 486 * 0.60
127
 
128
  # --- Calculations ---
129
 
130
+ # 1. Calculate Emissions Factor
 
131
  if turbine_eff_percent > 0:
132
  calculated_ef = FUEL_CARBON_CONSTANT / (turbine_eff_percent / 100)
133
  else:
 
138
  total_gwh = gas_gw_capacity * CAPACITY_FACTOR * 8760
139
 
140
  # 3. Calculate Emissions (MMT CO2e)
 
 
141
  ai_emissions_mmt = (total_gwh * calculated_ef) / 1_000_000
 
142
  percent_increase = (ai_emissions_mmt / US_BASELINE_MMT) * 100
143
 
144
  # --- Dashboard Layout ---
145
 
146
+ # 1. The Big Number
147
  c1, c2, c3 = st.columns([1, 2, 1])
148
  with c2:
149
  st.markdown(f"""
150
  <div class="metric-card">
151
+ <div class="sub-text">Projected US Emissions Increase</div>
152
  <div class="big-number">+{percent_increase:.2f}%</div>
153
  <div class="sub-text">({ai_emissions_mmt:.1f} Million tCO2e)</div>
154
+ <div style="font-size: 1em; color: #888; margin-top: 10px;">
155
+ Based on {gas_share}% Gas Share & {turbine_eff_percent}%
156
  </div>
157
  </div>
158
  """, unsafe_allow_html=True)
159
 
160
+ # 2. Charts
 
 
161
  st.subheader("US Emissions Trajectory vs. AI Impact")
162
 
163
+ years = [2015, 2020, 2023]
164
+ emissions_hist = [6600, 6000, 6200]
165
+ target_2030 = 7200 * 0.50
166
+ bau_2030 = 5800
 
167
 
168
  fig1 = go.Figure()
169
 
 
170
  fig1.add_trace(go.Scatter(
171
  x=years, y=emissions_hist,
172
  mode='lines+markers',
 
174
  line=dict(color='gray', width=2)
175
  ))
176
 
 
177
  fig1.add_trace(go.Scatter(
178
  x=[2023, 2030], y=[6200, target_2030],
179
  mode='lines',
 
181
  line=dict(color='green', dash='dash', width=2)
182
  ))
183
 
 
184
  fig1.add_trace(go.Bar(
185
  x=[2030], y=[bau_2030],
186
  name='2030 Baseline Estimate',
 
202
  hovermode="x unified"
203
  )
204
 
 
205
  st.plotly_chart(fig1, use_container_width=True)
206
 
 
207
  st.markdown("---")
208
  with st.expander("📚 Data Sources & Methodology"):
209
  st.markdown(f"""
 
212
  * **Efficiency Logic:** Emissions Factor is calculated dynamically based on the **Electrical Efficiency** slider ({turbine_eff_percent}% currently selected).
213
  * *Formula:* `EF = (Benchmark Carbon Content) / Efficiency %`
214
  * *Benchmark:* Based on standard NREL data for CCGT (486 gCO2e/kWh @ 60% efficiency).
 
 
 
215
  """)