vdwow commited on
Commit
bb4818f
·
verified ·
1 Parent(s): fdd0b05

Add informations about equivalent and how to reduce impacts, add LinkedIn CTA

Browse files
Files changed (1) hide show
  1. app.py +134 -85
app.py CHANGED
@@ -15,6 +15,9 @@ u.define('kgCO2eq = kilogram')
15
  u.define('kgSbeq = kilogram')
16
  u.define('MJ = megajoule')
17
  u.define('kJ = kilojoule')
 
 
 
18
  q = u.Quantity
19
 
20
 
@@ -64,21 +67,31 @@ def format_indicator(name: str, value: str, unit: str) -> str:
64
 
65
 
66
  def form_output(impacts):
 
67
  energy_ = q(impacts.energy.value, impacts.energy.unit)
 
68
  if energy_ < q("1 kWh"):
69
  energy_ = energy_.to("Wh")
 
 
70
  gwp_ = q(impacts.gwp.value, impacts.gwp.unit)
 
71
  if gwp_ < q("1 kgCO2eq"):
72
  gwp_ = gwp_.to("1 gCO2eq")
 
73
  adpe_ = q(impacts.adpe.value, impacts.adpe.unit)
 
74
  pe_ = q(impacts.pe.value, impacts.pe.unit)
75
  if pe_ < q("1 MJ"):
76
  pe_ = pe_.to("kJ")
 
77
  return (
78
  format_indicator("⚡️ Energy", f"{energy_.magnitude:.3g}", energy_.units),
79
  format_indicator("🌍 GHG Emissions", f"{gwp_.magnitude:.3g}", gwp_.units),
80
  format_indicator("🪨 Abiotic Resources", f"{adpe_.magnitude:.3g}", adpe_.units),
81
  format_indicator("⛽️ Primary Energy", f"{pe_.magnitude:.3g}", pe_.units),
 
 
82
  )
83
 
84
 
@@ -130,112 +143,148 @@ with gr.Blocks() as demo:
130
  **generative AI** models through APIs.
131
 
132
  Read the documentation:
133
- [ecologits.ai](https://ecologits.ai) | ⭐️ us on GitHub: [genai-impact/ecologits](https://github.com/genai-impact/ecologits)
 
134
  """)
135
 
136
  ### SIMPLE CALCULATOR
 
 
 
 
137
 
138
- gr.Markdown("""
139
- ## 😊 Calculator
140
- """)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
141
 
142
- with gr.Row():
 
 
 
 
143
  model = gr.Dropdown(
144
  MODELS,
145
  label="Model name",
146
  value="openai/gpt-3.5-turbo",
147
  filterable=True,
148
  )
149
- prompt = gr.Dropdown(
150
- PROMPTS,
151
- label="Example prompt",
152
- value=50
153
  )
154
-
155
- with gr.Row():
156
- energy = gr.Markdown(
157
- label="energy",
158
- latex_delimiters=[{"left": "$$", "right": "$$", "display": False}]
159
- )
160
- gwp = gr.Markdown(
161
- label="gwp",
162
- latex_delimiters=[{"left": "$$", "right": "$$", "display": False}]
163
  )
164
- adpe = gr.Markdown(
165
- label="adpe",
166
- latex_delimiters=[{"left": "$$", "right": "$$", "display": False}]
167
  )
168
- pe = gr.Markdown(
169
- label="pe",
170
- latex_delimiters=[{"left": "$$", "right": "$$", "display": False}]
171
  )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
172
 
173
- submit_btn = gr.Button("Submit")
174
- submit_btn.click(fn=form, inputs=[model, prompt], outputs=[energy, gwp, adpe, pe])
175
-
176
- ### EXPERT CALCULATOR
177
-
178
- gr.Markdown("""
179
- ## 🤓 Expert mode
180
- """)
181
- model = gr.Dropdown(
182
- MODELS,
183
- label="Model name",
184
- value="openai/gpt-3.5-turbo",
185
- filterable=True,
186
- )
187
- tokens = gr.Number(
188
- label="Output tokens",
189
- value=100
190
- )
191
- mix_gwp = gr.Number(
192
- label="Electricity mix - GHG emissions [kgCO2eq / kWh]",
193
- value=IF_ELECTRICITY_MIX_GWP
194
- )
195
- mix_adpe = gr.Number(
196
- label="Electricity mix - Abiotic resources [kgSbeq / kWh]",
197
- value=IF_ELECTRICITY_MIX_ADPE
198
- )
199
- mix_pe = gr.Number(
200
- label="Electricity mix - Primary energy [MJ / kWh]",
201
- value=IF_ELECTRICITY_MIX_PE
202
- )
203
-
204
- with gr.Row():
205
- energy = gr.Markdown(
206
- label="energy",
207
- latex_delimiters=[{"left": "$$", "right": "$$", "display": False}]
208
- )
209
- gwp = gr.Markdown(
210
- label="gwp",
211
- latex_delimiters=[{"left": "$$", "right": "$$", "display": False}]
212
- )
213
- adpe = gr.Markdown(
214
- label="adpe",
215
- latex_delimiters=[{"left": "$$", "right": "$$", "display": False}]
216
- )
217
- pe = gr.Markdown(
218
- label="pe",
219
- latex_delimiters=[{"left": "$$", "right": "$$", "display": False}]
220
  )
221
 
222
- submit_btn = gr.Button("Submit")
223
- submit_btn.click(
224
- fn=form_expert,
225
- inputs=[model, tokens, mix_gwp, mix_adpe, mix_pe],
226
- outputs=[energy, gwp, adpe, pe]
227
- )
228
 
229
  ### INFORMATION ABOUT INDICATORS
 
 
 
 
 
 
 
230
 
231
- gr.Markdown("""
232
- ## 📊 More about the indicators
233
-
234
- - ⚡️ **Energy**: Final energy consumption,
235
- - 🌍 **GHG Emissions**: Potential impact on global warming (commonly known as GHG/carbon emissions),
236
- - 🪨 **Abiotic Resources**: Impact on the depletion of non-living resources such as minerals or metals,
237
- - ⛽️ **Primary Energy**: Total energy consumed from primary sources.
238
- """)
 
 
 
 
 
 
 
 
 
 
 
 
239
 
240
  if __name__ == '__main__':
241
  demo.launch()
 
15
  u.define('kgSbeq = kilogram')
16
  u.define('MJ = megajoule')
17
  u.define('kJ = kilojoule')
18
+ u.define('m = meter')
19
+ u.define('km = kilometer')
20
+ u.define('episodes = number of episodes')
21
  q = u.Quantity
22
 
23
 
 
67
 
68
 
69
  def form_output(impacts):
70
+
71
  energy_ = q(impacts.energy.value, impacts.energy.unit)
72
+ eq_energy_ = q(impacts.energy.value * 2, 'km')
73
  if energy_ < q("1 kWh"):
74
  energy_ = energy_.to("Wh")
75
+ eq_energy_ = q(impacts.energy.value * 2000, 'm')
76
+
77
  gwp_ = q(impacts.gwp.value, impacts.gwp.unit)
78
+ eq_gwp_ = q(impacts.gwp.value / 0.032, 'episodes')
79
  if gwp_ < q("1 kgCO2eq"):
80
  gwp_ = gwp_.to("1 gCO2eq")
81
+ eq_gwp_ = q(impacts.gwp.value / 0.032, 'episodes')
82
  adpe_ = q(impacts.adpe.value, impacts.adpe.unit)
83
+
84
  pe_ = q(impacts.pe.value, impacts.pe.unit)
85
  if pe_ < q("1 MJ"):
86
  pe_ = pe_.to("kJ")
87
+
88
  return (
89
  format_indicator("⚡️ Energy", f"{energy_.magnitude:.3g}", energy_.units),
90
  format_indicator("🌍 GHG Emissions", f"{gwp_.magnitude:.3g}", gwp_.units),
91
  format_indicator("🪨 Abiotic Resources", f"{adpe_.magnitude:.3g}", adpe_.units),
92
  format_indicator("⛽️ Primary Energy", f"{pe_.magnitude:.3g}", pe_.units),
93
+ format_indicator("🔋 Equivalent energy : distance with a small electric car", f"{eq_energy_.magnitude:.3g}", eq_energy_.units),
94
+ format_indicator("🏰 Equivalent emissions for 1000 prompts : watching GoT in streaming", f"{eq_gwp_.magnitude:.3g}", eq_gwp_.units)
95
  )
96
 
97
 
 
143
  **generative AI** models through APIs.
144
 
145
  Read the documentation:
146
+ [ecologits.ai](https://ecologits.ai) | ⭐️ us on GitHub: [genai-impact/ecologits](https://github.com/genai-impact/ecologits) |
147
+ Follow us on Linkedin ✅: [GenAI Impact](https://www.linkedin.com/company/genai-impact/posts/?feedView=all)
148
  """)
149
 
150
  ### SIMPLE CALCULATOR
151
+ with gr.Tab("Home"):
152
+ gr.Markdown("""
153
+ ## 😊 Calculator
154
+ """)
155
 
156
+ with gr.Row():
157
+ model = gr.Dropdown(
158
+ MODELS,
159
+ label="Model name",
160
+ value="openai/gpt-3.5-turbo",
161
+ filterable=True,
162
+ )
163
+ prompt = gr.Dropdown(
164
+ PROMPTS,
165
+ label="Example prompt",
166
+ value=50
167
+ )
168
+
169
+ with gr.Row():
170
+ energy = gr.Markdown(
171
+ label="energy",
172
+ latex_delimiters=[{"left": "$$", "right": "$$", "display": False}]
173
+ )
174
+ gwp = gr.Markdown(
175
+ label="gwp",
176
+ latex_delimiters=[{"left": "$$", "right": "$$", "display": False}]
177
+ )
178
+ adpe = gr.Markdown(
179
+ label="adpe",
180
+ latex_delimiters=[{"left": "$$", "right": "$$", "display": False}]
181
+ )
182
+ pe = gr.Markdown(
183
+ label="pe",
184
+ latex_delimiters=[{"left": "$$", "right": "$$", "display": False}]
185
+ )
186
+
187
+ gr.Markdown('---')
188
+
189
+ with gr.Row():
190
+ equivalent_1 = gr.Markdown(
191
+ label="eq_energy",
192
+ latex_delimiters=[{"left": "$$", "right": "$$", "display": False}]
193
+ )
194
+ equivalent_2 = gr.Markdown(
195
+ label="eq_gwp",
196
+ latex_delimiters=[{"left": "$$", "right": "$$", "display": False}]
197
+ )
198
+
199
+ submit_btn = gr.Button("Submit")
200
+ submit_btn.click(fn=form, inputs=[model, prompt], outputs=[energy, gwp, adpe, pe, equivalent_1, equivalent_2])
201
 
202
+ ### EXPERT CALCULATOR
203
+ with gr.Tab("Expert Mode"):
204
+ gr.Markdown("""
205
+ ## 🤓 Expert mode
206
+ """)
207
  model = gr.Dropdown(
208
  MODELS,
209
  label="Model name",
210
  value="openai/gpt-3.5-turbo",
211
  filterable=True,
212
  )
213
+ tokens = gr.Number(
214
+ label="Output tokens",
215
+ value=100
 
216
  )
217
+ mix_gwp = gr.Number(
218
+ label="Electricity mix - GHG emissions [kgCO2eq / kWh]",
219
+ value=IF_ELECTRICITY_MIX_GWP
 
 
 
 
 
 
220
  )
221
+ mix_adpe = gr.Number(
222
+ label="Electricity mix - Abiotic resources [kgSbeq / kWh]",
223
+ value=IF_ELECTRICITY_MIX_ADPE
224
  )
225
+ mix_pe = gr.Number(
226
+ label="Electricity mix - Primary energy [MJ / kWh]",
227
+ value=IF_ELECTRICITY_MIX_PE
228
  )
229
+
230
+ with gr.Row():
231
+ energy = gr.Markdown(
232
+ label="energy",
233
+ latex_delimiters=[{"left": "$$", "right": "$$", "display": False}]
234
+ )
235
+ gwp = gr.Markdown(
236
+ label="gwp",
237
+ latex_delimiters=[{"left": "$$", "right": "$$", "display": False}]
238
+ )
239
+ adpe = gr.Markdown(
240
+ label="adpe",
241
+ latex_delimiters=[{"left": "$$", "right": "$$", "display": False}]
242
+ )
243
+ pe = gr.Markdown(
244
+ label="pe",
245
+ latex_delimiters=[{"left": "$$", "right": "$$", "display": False}]
246
+ )
247
 
248
+ submit_btn = gr.Button("Submit")
249
+ submit_btn.click(
250
+ fn=form_expert,
251
+ inputs=[model, tokens, mix_gwp, mix_adpe, mix_pe],
252
+ outputs=[energy, gwp, adpe, pe]
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
253
  )
254
 
255
+ ### METHOD QUICK EXPLANATION
256
+ with gr.Tab('Methodology'):
257
+ gr.Markdown("""##📖 Coming soon""")
 
 
 
258
 
259
  ### INFORMATION ABOUT INDICATORS
260
+ with gr.Accordion("📊 More about the indicators", open = False):
261
+ gr.Markdown("""
262
+ - ⚡️ **Energy**: Final energy consumption,
263
+ - 🌍 **GHG Emissions**: Potential impact on global warming (commonly known as GHG/carbon emissions),
264
+ - 🪨 **Abiotic Resources**: Impact on the depletion of non-living resources such as minerals or metals,
265
+ - ⛽️ **Primary Energy**: Total energy consumed from primary sources.
266
+ """)
267
 
268
+ ### INFORMATION ABOUT REDUCING IMPACTS
269
+ with gr.Accordion("📉 How to reduce / limit these impacts ?", open = False):
270
+ gr.Markdown("""
271
+
272
+ * **Fundamental rule** : Show **sobriety** on the uses of (generative) AI :
273
+ * Questionning the usefulness of the project ;
274
+ * Estimating impacts of the project ;
275
+ * Evaluating the project purpose ;
276
+ * Restricting the use case to the desired purposes
277
+
278
+ * 🦾 On the hardware side :
279
+ * If you can, try to relocate the computing in low emissions and/or energy efficient datacenters
280
+
281
+ * 🤖 On the ML side :
282
+ * Develop a zero-shot learning approach for general tasks ;
283
+ * Prefer the smaller and yet well-peforming models (using number of parameters for example)
284
+ * If a specialization is needed, always prefer fine-tuning an existing model than re-training one from scratch ;
285
+ * During model inference, try caching the most popular prompts ("hey, tell me a joke about ...")
286
+
287
+ """)
288
 
289
  if __name__ == '__main__':
290
  demo.launch()