TheoLvs commited on
Commit
d271714
1 Parent(s): 871aa55

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +123 -89
app.py CHANGED
@@ -103,8 +103,8 @@ def chat(
103
  complete_response = ""
104
  messages.pop()
105
  else:
106
- sources = "No environmental report was used to provide this answer."
107
- complete_response = "No relevant documents found, for a sourced answer you may want to try a more specific question.\n\n"
108
 
109
  messages.append({"role": "assistant", "content": complete_response})
110
  timestamp = str(datetime.now().timestamp())
@@ -157,99 +157,133 @@ css_code = ".gradio-container {background-image: url('file=background.png');back
157
  with gr.Blocks(title="🌍 ClimateGPT Ekimetrics", css=css_code) as demo:
158
  user_id_state = gr.State([user_id])
159
 
160
- with gr.Tab("App"):
161
- gr.Markdown("# Welcome to Climate GPT 🌍 !")
162
- gr.Markdown(
163
- """ Climate GPT is an interactive exploration tool designed to help you easily find relevant information based on of Environmental reports such as IPCCs and other environmental reports.
164
- \n **How does it work:** when a user sends a message, the system retrieves the most relevant paragraphs from scientific reports that are semantically related to the user's question. These paragraphs are then used to generate a comprehensive and well-sourced answer using a language model.
165
- \n **Usage guideline:** the more specific your questions, the more relevant will the documents retrieved be.
166
- \n ⚠️ Always refer to the source to ensure the validity of the information communicated.
167
- """
168
- )
169
- with gr.Row():
170
- with gr.Column(scale=2):
171
- chatbot = gr.Chatbot(elem_id="chatbot")
172
- state = gr.State([system_template])
173
-
174
- with gr.Row():
175
- ask = gr.Textbox(
176
- show_label=False,
177
- placeholder="Enter text and press enter",
178
- sample_inputs=["which country polutes the most ?"],
179
- ).style(container=False)
180
-
181
- with gr.Column(scale=1, variant="panel"):
182
- gr.Markdown("### Sources")
183
- sources_textbox = gr.Textbox(
184
- interactive=False, show_label=False, max_lines=50
185
- )
186
- ask.submit(
187
- fn=chat,
188
- inputs=[
189
- user_id_state,
190
- ask,
191
- state,
192
- gr.inputs.Dropdown(
193
- ["IPCC only", "All available"],
194
- default="All available",
195
- label="Select reports",
196
- ),
197
- ],
198
- outputs=[chatbot, state, sources_textbox],
199
- )
200
- ask.submit(reset_textbox, [], [ask])
201
-
202
- with gr.Accordion("Feedbacks", open=False):
203
- gr.Markdown("Please complete some feedbacks 🙏")
204
- feedback = gr.Textbox()
205
- feedback_save = gr.Button(value="submit feedback")
206
- # thanks = gr.Textbox()
207
- feedback_save.click(
208
- save_feedback,
209
- inputs=[feedback, user_id_state], # outputs=[thanks]
210
- )
211
 
212
- with gr.Accordion("Add your personal openai api key - Option", open=False):
213
- openai_api_key_textbox = gr.Textbox(
214
- placeholder="Paste your OpenAI API key (sk-...) and hit Enter",
215
- show_label=False,
216
- lines=1,
217
- type="password",
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
218
  )
219
- openai_api_key_textbox.change(
220
- set_openai_api_key, inputs=[openai_api_key_textbox]
221
- )
222
- openai_api_key_textbox.submit(
223
- set_openai_api_key, inputs=[openai_api_key_textbox]
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
224
  )
225
 
226
- with gr.Tab("Information"):
227
- gr.Markdown(
228
- """
229
- ## 📖 Reports used : \n
230
- - First Assessment Report on the Physical Science of Climate Change
231
- - Second assessment Report on Climate Change Adaptation
232
- - Third Assessment Report on Climate Change Mitigation
233
- - Food Outlook Biannual Report on Global Food Markets
234
- - IEA's report on the Role of Critical Minerals in Clean Energy Transitions
235
- - Limits to Growth
236
- - Outside The Safe operating system of the Planetary Boundary for Novel Entities
237
- - Planetary Boundaries Guiding
238
- - State of the Oceans report
239
- - Word Energy Outlook 2021
240
- - Word Energy Outlook 2022
241
- - The environmental impacts of plastics and micro plastics use, waste and polution ET=U and national measures
242
- - IPBES Global report - MArch 2022
243
-
244
- \n
245
- IPCC is a United Nations body that assesses the science related to climate change, including its impacts and possible response options.
246
- The IPCC is considered the leading scientific authority on all things related to global climate change.
247
-
248
- """
249
  )
250
- with gr.Tab("Examples"):
251
- gr.Markdown("See here some examples on how to use the Chatbot")
 
 
 
 
252
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
253
  demo.queue(concurrency_count=16)
254
 
255
  demo.launch()
 
103
  complete_response = ""
104
  messages.pop()
105
  else:
106
+ sources = "No climate science report was used to provide this answer."
107
+ complete_response = "No relevant documents found in the climate science reports, for a sourced answer you may want to try a more specific question.\n\n"
108
 
109
  messages.append({"role": "assistant", "content": complete_response})
110
  timestamp = str(datetime.now().timestamp())
 
157
  with gr.Blocks(title="🌍 ClimateGPT Ekimetrics", css=css_code) as demo:
158
  user_id_state = gr.State([user_id])
159
 
160
+ gr.Markdown("# Welcome to Climate.GPT 🌍 !")
161
+ gr.Markdown(
162
+ """
163
+ Climate change and environmental disruptions have become some of the most pressing challenges facing our planet today. As global temperatures rise and ecosystems suffer, it is essential for individuals to understand the gravity of the situation in order to make informed decisions and advocate for appropriate policy changes.
164
+
165
+ However, comprehending the vast and complex scientific information can be daunting, as the scientific consensus references, such as the Intergovernmental Panel on Climate Change (IPCC) reports, span thousands of pages and are often laden with technical jargon. To bridge this gap and make climate science more accessible, we introduce ClimateGPT as a tool to distill expert-level knowledge into easily digestible insights about climate science.
166
+
167
+ ClimateGPT harnesses modern OCR techniques to parse and preprocess IPCC reports. By leveraging state-of-the-art question-answering algorithms, ClimateGPT is able to sift through the extensive collection of climate scientific reports and identify relevant passages in response to user inquiries. Furthermore, the integration of the ChatGPT API allows ClimateGPT to present complex data in a user-friendly manner, summarizing key points and facilitating communication of climate science to a wider audience. This innovative chatbot effectively puts a climate expert in your pocket, empowering you to engage with crucial environmental issues in a more informed and meaningful way.
168
+ ## How to use Climate GPT
169
+
170
+ ### Getting started
171
+
172
+ - In the chatbot section, simply type your climate-related question, and ClimateGPT will provide an answer with references to relevant IPCC reports.
173
+ - ClimateGPT retrieves specific passages from the IPCC reports to help answer your question accurately.
174
+ - Source information, including page numbers and passages, is displayed on the right side of the screen for easy verification.
175
+ - Feel free to ask follow-up questions within the chatbot for a more in-depth understanding.
176
+ - ClimateGPT integrates multiple sources (IPCC, IPBES, IEA, Limits to Growth, … ) to cover various aspects of environmental science, such as climate change, biodiversity, energy, economy, and pollution. See all sources used below.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
177
 
178
+ ### Limitations
179
+
180
+ - Currently available in English only.
181
+ - ⚠️ Please note that, like any AI, the model may occasionally generate an inaccurate or imprecise answer. Always refer to the provided sources to verify the validity of the information given. If you find any issues with the response, kindly provide feedback to help improve the system.
182
+ - ClimateGPT is specifically designed for climate-related inquiries. If you ask a non-environmental question, the chatbot will politely remind you that its focus is on climate and environmental issues.
183
+ """
184
+ )
185
+ with gr.Row():
186
+ with gr.Column(scale=2):
187
+ chatbot = gr.Chatbot(elem_id="chatbot")
188
+ state = gr.State([system_template])
189
+
190
+ with gr.Row():
191
+ ask = gr.Textbox(
192
+ show_label=False,
193
+ placeholder="Ask here your climate-related question and press enter",
194
+ sample_inputs=["which country polutes the most ?"],
195
+ ).style(container=False)
196
+
197
+ with gr.Column(scale=1, variant="panel"):
198
+ gr.Markdown("### Sources")
199
+ sources_textbox = gr.Textbox(
200
+ interactive=False, show_label=False, max_lines=50
201
  )
202
+ ask.submit(
203
+ fn=chat,
204
+ inputs=[
205
+ user_id_state,
206
+ ask,
207
+ state,
208
+ gr.inputs.Dropdown(
209
+ ["IPCC only", "All available"],
210
+ default="All available",
211
+ label="Select reports",
212
+ ),
213
+ ],
214
+ outputs=[chatbot, state, sources_textbox],
215
+ )
216
+ ask.submit(reset_textbox, [], [ask])
217
+
218
+ with gr.Accordion("Submit here your feedbacks and feature requests🙏", open=False):
219
+ gr.Markdown("""
220
+ ## Beta test
221
+
222
+ - ClimateGPT welcomes community contributions. To participate, head over to the Community Tab and create a "New Discussion" to ask questions and share your insights.
223
+ - Provide feedback through our feedback form, letting us know which insights you found accurate, useful, or not. Your input will help us improve the platform.
224
+ - To make climate science accessible to a wider audience, we have opened our own OpenAI API key with a monthly cap of $1000. If you already have an API key, please use it to help conserve bandwidth for others.
225
+
226
+ ## Feedbacks
227
+ """)
228
+
229
+ feedback = gr.Textbox()
230
+ feedback_save = gr.Button(value="submit feedback")
231
+ # thanks = gr.Textbox()
232
+ feedback_save.click(
233
+ save_feedback,
234
+ inputs=[feedback, user_id_state], # outputs=[thanks]
235
  )
236
 
237
+ with gr.Accordion("Add your personal openai api key - Optional (see beta-test section below)", open=False):
238
+ openai_api_key_textbox = gr.Textbox(
239
+ placeholder="Paste your OpenAI API key (sk-...) and hit Enter",
240
+ show_label=False,
241
+ lines=1,
242
+ type="password",
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
243
  )
244
+ openai_api_key_textbox.change(
245
+ set_openai_api_key, inputs=[openai_api_key_textbox]
246
+ )
247
+ openai_api_key_textbox.submit(
248
+ set_openai_api_key, inputs=[openai_api_key_textbox]
249
+ )
250
 
251
+ gr.Markdown("""
252
+
253
+
254
+ ## Sources
255
+
256
+ | IPCC | IPCC AR6 - First Assessment Report on the Physical Science of Climate Change | https://report.ipcc.ch/ar6/wg1/IPCC_AR6_WGI_FullReport.pdf | 2049 pages | August 2021 |
257
+ | --- | --- | --- | --- | --- |
258
+ | IPCC | IPCC AR6 - Second Assessment Report on Climate Change Adaptation | https://report.ipcc.ch/ar6/wg2/IPCC_AR6_WGII_FullReport.pdf | 3068 pages | February 2022 |
259
+ | IPCC | IPCC AR6 - Third Assessment Report on Climate Change Mitigation | https://www.ipcc.ch/report/ar6/wg3/downloads/report/IPCC_AR6_WGIII_FullReport.pdf | 2258 pages | April 2022 |
260
+ | IPCC | IPCC AR6 - Synthesis Report of the IPCC 6th assessment report (AR6) | https://report.ipcc.ch/ar6syr/pdf/IPCC_AR6_SYR_SPM.pdf | 36 pages | March 2023 |
261
+ | IPBES | IPBES Global report on Biodiversity - March 2022 | https://www.ipbes.net/global-assessment | 1148 pages | June 2022 |
262
+ | FAO | Food Outlook Biannual Report on Global Food Markets | https://www.fao.org/documents/card/en/c/cb9427en | 174 pages | June 2022 |
263
+ | IEA | IEA’s report on the Role of Critical Minerals in Clean Energy Transitions | https://www.iea.org/reports/the-role-of-critical-minerals-in-clean-energy-transitions | 287 pages | May 2021 |
264
+ | Club de Rome | Limits to Growth | https://www.donellameadows.org/wp-content/userfiles/Limits-to-Growth-digital-scan-version.pdf | 211 pages | 1972 |
265
+ | | Outside The Safe operating system of the Planetary Boundary for Novel Entities | https://pubs.acs.org/doi/10.1021/acs.est.1c04158 | 12 pages | January 2022 |
266
+ | | Planetary boundaries: Guiding human development on a changing planet | https://www.science.org/doi/10.1126/science.1259855 | 11 pages | February 2015 |
267
+ | UNFCCC | State of the Oceans report | https://unfccc.int/documents/568128 | 75 pages | August 2022 |
268
+ | IEA | Word Energy Outlook 2021 | https://www.iea.org/reports/world-energy-outlook-2021 | 386 pages | October 2021 |
269
+ | IEA | Word Energy Outlook 2022 | https://www.iea.org/reports/world-energy-outlook-2022 | 524 pages | October 2022 |
270
+ | EU parliament | The environmental impacts of plastics and micro plastics use, waste and polution EU and national measures | https://www.europarl.europa.eu/thinktank/en/document/IPOL_STU(2020)658279 | 76 pages | October 2020 |
271
+
272
+ ## Carbon Footprint
273
+
274
+ Carbon emissions were measured during the development and inference process using CodeCarbon [https://github.com/mlco2/codecarbon](https://github.com/mlco2/codecarbon)
275
+
276
+ | Phase | Description | Emissions | Source |
277
+ | --- | --- | --- | --- |
278
+ | Development | OCR and parsing all pdf documents with AI | x kgCO2 | CodeCarbon |
279
+ | Development | Question Answering development | x kgCO2 | CodeCarbon |
280
+ | Inference | Question Answering | x kgCO2 / call | CodeCarbon |
281
+ | Inference | API call to turbo-GPT | x kgCO2 / call | OpenAI |
282
+
283
+ ## Authors
284
+ - Ekimetrics
285
+ """)
286
+
287
  demo.queue(concurrency_count=16)
288
 
289
  demo.launch()