TheoLvs commited on
Commit
887905a
β€’
1 Parent(s): 37b1e7a

CSS update + IPOS

Browse files
README.md CHANGED
@@ -4,7 +4,7 @@ emoji: 🌍
4
  colorFrom: blue
5
  colorTo: red
6
  sdk: gradio
7
- sdk_version: 4.2.0
8
  app_file: app.py
9
  fullWidth: true
10
  pinned: false
 
4
  colorFrom: blue
5
  colorTo: red
6
  sdk: gradio
7
+ sdk_version: 4.19.1
8
  app_file: app.py
9
  fullWidth: true
10
  pinned: false
app.py CHANGED
@@ -10,6 +10,8 @@ import time
10
  import re
11
  import json
12
 
 
 
13
  from io import BytesIO
14
  import base64
15
 
@@ -108,28 +110,13 @@ def serialize_docs(docs):
108
  return new_docs
109
 
110
 
111
- # import asyncio
112
- # from typing import Any, Dict, List
113
- # from langchain.callbacks.base import AsyncCallbackHandler, BaseCallbackHandler
114
-
115
- # class MyCustomAsyncHandler(AsyncCallbackHandler):
116
- # """Async callback handler that can be used to handle callbacks from langchain."""
117
-
118
- # async def on_chain_start(
119
- # self, serialized: Dict[str, Any], inputs: Dict[str, Any], **kwargs: Any
120
- # ) -> Any:
121
- # """Run when chain starts running."""
122
- # print("zzzz....")
123
- # await asyncio.sleep(3)
124
- # print(f"on_chain_start {serialized['name']}")
125
- # # raise gr.Error("ClimateQ&A Error: Timeout, try another question and if the error remains, you can contact us :)")
126
-
127
-
128
 
129
  async def chat(query,history,audience,sources,reports):
130
  """taking a query and a message history, use a pipeline (reformulation, retriever, answering) to yield a tuple of:
131
  (messages in gradio format, messages in langchain format, source documents)"""
132
 
 
 
133
  if audience == "Children":
134
  audience_prompt = audience_prompts["children"]
135
  elif audience == "General public":
@@ -189,8 +176,10 @@ async def chat(query,history,audience,sources,reports):
189
 
190
  elif op['path'] == path_answer: # final answer
191
  new_token = op['value'] # str
192
- time.sleep(0.01)
193
- answer_yet = history[-1][1] + new_token
 
 
194
  answer_yet = parse_output_llm_with_sources(answer_yet)
195
  history[-1] = (query,answer_yet)
196
 
@@ -324,16 +313,12 @@ def make_html_source(source,i):
324
  else:
325
  break
326
  toc_levels = " > ".join(toc_levels)
327
- print(toc_levels)
328
 
329
  if len(toc_levels) > 0:
330
  name = f"<b>{toc_levels}</b><br/>{meta['name']}"
331
  else:
332
  name = meta['name']
333
 
334
- print(name)
335
-
336
-
337
  if meta["chunk_type"] == "text":
338
 
339
  card = f"""
@@ -404,12 +389,7 @@ def save_feedback(feed: str, user_id):
404
  def log_on_azure(file, logs, share_client):
405
  logs = json.dumps(logs)
406
  file_client = share_client.get_file_client(file)
407
- print("Uploading logs to Azure Blob Storage")
408
- print("----------------------------------")
409
- print("")
410
- print(logs)
411
  file_client.upload_file(logs)
412
- print("Logs uploaded to Azure Blob Storage")
413
 
414
 
415
  # --------------------------------------------------------------------
@@ -459,7 +439,8 @@ with gr.Blocks(title="Climate Q&A", css="style.css", theme=theme,elem_id = "main
459
 
460
 
461
  with gr.Row(elem_id = "input-message"):
462
- textbox=gr.Textbox(placeholder="Ask me anything here!",show_label=False,scale=1,lines = 1,interactive = True)
 
463
 
464
 
465
  with gr.Column(scale=1, variant="panel",elem_id = "right-panel"):
@@ -497,13 +478,14 @@ with gr.Blocks(title="Climate Q&A", css="style.css", theme=theme,elem_id = "main
497
  sources_textbox = gr.HTML(show_label=False, elem_id="sources-textbox")
498
  docs_textbox = gr.State("")
499
 
 
500
  with gr.Tab("Configuration",elem_id = "tab-config",id = 2):
501
 
502
  gr.Markdown("Reminder: You can talk in any language, ClimateQ&A is multi-lingual!")
503
 
504
 
505
  dropdown_sources = gr.CheckboxGroup(
506
- ["IPCC", "IPBES"],
507
  label="Select source",
508
  value=["IPCC"],
509
  interactive=True,
@@ -539,202 +521,15 @@ with gr.Blocks(title="Climate Q&A", css="style.css", theme=theme,elem_id = "main
539
  with gr.Tab("Figures",elem_id = "tab-images",elem_classes = "max-height other-tabs"):
540
  gallery_component = gr.Gallery()
541
 
542
- with gr.Tab("About ClimateQ&A",elem_classes = "max-height other-tabs"):
543
  with gr.Row():
544
  with gr.Column(scale=1):
545
- gr.Markdown(
546
- """
547
- <p><b>Climate change and environmental disruptions have become some of the most pressing challenges facing our planet today</b>. 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.</p>
548
- <p>However, comprehending the vast and complex scientific information can be daunting, as the scientific consensus references, such as <b>the Intergovernmental Panel on Climate Change (IPCC) reports, span thousands of pages</b>. To bridge this gap and make climate science more accessible, we introduce <b>ClimateQ&A as a tool to distill expert-level knowledge into easily digestible insights about climate science.</b></p>
549
- <div class="tip-box">
550
- <div class="tip-box-title">
551
- <span class="light-bulb" role="img" aria-label="Light Bulb">πŸ’‘</span>
552
- How does ClimateQ&A work?
553
- </div>
554
- ClimateQ&A harnesses modern OCR techniques to parse and preprocess IPCC reports. By leveraging state-of-the-art question-answering algorithms, <i>ClimateQ&A is able to sift through the extensive collection of climate scientific reports and identify relevant passages in response to user inquiries</i>. Furthermore, the integration of the ChatGPT API allows ClimateQ&A to present complex data in a user-friendly manner, summarizing key points and facilitating communication of climate science to a wider audience.
555
- </div>
556
- """
557
- )
558
-
559
- with gr.Column(scale=1):
560
- gr.Markdown("![](https://i.postimg.cc/fLvsvMzM/Untitled-design-5.png)")
561
- gr.Markdown("*Source : IPCC AR6 - Synthesis Report of the IPCC 6th assessment report (AR6)*")
562
-
563
- gr.Markdown("## How to use ClimateQ&A")
564
- with gr.Row():
565
- with gr.Column(scale=1):
566
- gr.Markdown(
567
- """
568
- ### Getting started
569
- - In the chatbot section, simply type your climate-related question, and ClimateQ&A will provide an answer with references to relevant IPCC reports.
570
- - ClimateQ&A retrieves specific passages from the IPCC reports to help answer your question accurately.
571
- - Source information, including page numbers and passages, is displayed on the right side of the screen for easy verification.
572
- - Feel free to ask follow-up questions within the chatbot for a more in-depth understanding.
573
- - You can ask question in any language, ClimateQ&A is multi-lingual !
574
- - ClimateQ&A integrates multiple sources (IPCC and IPBES, … ) to cover various aspects of environmental science, such as climate change and biodiversity. See all sources used below.
575
- """
576
- )
577
- with gr.Column(scale=1):
578
- gr.Markdown(
579
- """
580
- ### Limitations
581
- <div class="warning-box">
582
- <ul>
583
- <li>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.</li>
584
- <li>ClimateQ&A 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.</li>
585
- </div>
586
- """
587
- )
588
-
589
-
590
- with gr.Tab("Contact, feedback and feature requests",elem_classes = "max-height other-tabs"):
591
- gr.Markdown(
592
- """
593
-
594
- For any question or press request, contact ThΓ©o Alves Da Costa at <b>theo.alvesdacosta@ekimetrics.com</b>
595
-
596
- - ClimateQ&A welcomes community contributions. To participate, head over to the Community Tab and create a "New Discussion" to ask questions and share your insights.
597
- - Provide feedback through email, letting us know which insights you found accurate, useful, or not. Your input will help us improve the platform.
598
- - Only a few sources (see below) are integrated (all IPCC, IPBES), if you are a climate science researcher and net to sift through another report, please let us know.
599
-
600
- *This tool has been developed by the R&D lab at **Ekimetrics** (Jean Lelong, Nina Achache, Gabriel Olympie, Nicolas Chesneau, Natalia De la Calzada, ThΓ©o Alves Da Costa)*
601
- """
602
- )
603
- # with gr.Row():
604
- # with gr.Column(scale=1):
605
- # gr.Markdown("### Feedbacks")
606
- # feedback = gr.Textbox(label="Write your feedback here")
607
- # feedback_output = gr.Textbox(label="Submit status")
608
- # feedback_save = gr.Button(value="submit feedback")
609
- # feedback_save.click(
610
- # save_feedback,
611
- # inputs=[feedback, user_id_state],
612
- # outputs=feedback_output,
613
- # )
614
- # gr.Markdown(
615
- # "If you need us to ask another climate science report or ask any question, contact us at <b>theo.alvesdacosta@ekimetrics.com</b>"
616
- # )
617
-
618
- # with gr.Column(scale=1):
619
- # gr.Markdown("### OpenAI API")
620
- # gr.Markdown(
621
- # "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."
622
- # )
623
- # openai_api_key_textbox = gr.Textbox(
624
- # placeholder="Paste your OpenAI API key (sk-...) and hit Enter",
625
- # show_label=False,
626
- # lines=1,
627
- # type="password",
628
- # )
629
- # openai_api_key_textbox.change(set_openai_api_key, inputs=[openai_api_key_textbox])
630
- # openai_api_key_textbox.submit(set_openai_api_key, inputs=[openai_api_key_textbox])
631
-
632
- with gr.Tab("Sources",elem_classes = "max-height other-tabs"):
633
- gr.Markdown("""
634
- | Source | Report | URL | Number of pages | Release date |
635
- | --- | --- | --- | --- | --- |
636
- IPCC | Summary for Policymakers. In: Climate Change 2021: The Physical Science Basis. Contribution of the WGI to the AR6 of the IPCC. | https://www.ipcc.ch/report/ar6/wg1/downloads/report/IPCC_AR6_WGI_SPM.pdf | 32 | 2021
637
- IPCC | Full Report. In: Climate Change 2021: The Physical Science Basis. Contribution of the WGI to the AR6 of the IPCC. | https://report.ipcc.ch/ar6/wg1/IPCC_AR6_WGI_FullReport.pdf | 2409 | 2021
638
- IPCC | Technical Summary. In: Climate Change 2021: The Physical Science Basis. Contribution of the WGI to the AR6 of the IPCC. | https://www.ipcc.ch/report/ar6/wg1/downloads/report/IPCC_AR6_WGI_TS.pdf | 112 | 2021
639
- IPCC | Summary for Policymakers. In: Climate Change 2022: Impacts, Adaptation and Vulnerability. Contribution of the WGII to the AR6 of the IPCC. | https://www.ipcc.ch/report/ar6/wg2/downloads/report/IPCC_AR6_WGII_SummaryForPolicymakers.pdf | 34 | 2022
640
- IPCC | Technical Summary. In: Climate Change 2022: Impacts, Adaptation and Vulnerability. Contribution of the WGII to the AR6 of the IPCC. | https://www.ipcc.ch/report/ar6/wg2/downloads/report/IPCC_AR6_WGII_TechnicalSummary.pdf | 84 | 2022
641
- IPCC | Full Report. In: Climate Change 2022: Impacts, Adaptation and Vulnerability. Contribution of the WGII to the AR6 of the IPCC. | https://report.ipcc.ch/ar6/wg2/IPCC_AR6_WGII_FullReport.pdf | 3068 | 2022
642
- IPCC | Summary for Policymakers. In: Climate Change 2022: Mitigation of Climate Change. Contribution of the WGIII to the AR6 of the IPCC. | https://www.ipcc.ch/report/ar6/wg3/downloads/report/IPCC_AR6_WGIII_SummaryForPolicymakers.pdf | 50 | 2022
643
- IPCC | Technical Summary. In: Climate Change 2022: Mitigation of Climate Change. Contribution of the WGIII to the AR6 of the IPCC. | https://www.ipcc.ch/report/ar6/wg3/downloads/report/IPCC_AR6_WGIII_TechnicalSummary.pdf | 102 | 2022
644
- IPCC | Full Report. In: Climate Change 2022: Mitigation of Climate Change. Contribution of the WGIII to the AR6 of the IPCC. | https://www.ipcc.ch/report/ar6/wg3/downloads/report/IPCC_AR6_WGIII_FullReport.pdf | 2258 | 2022
645
- IPCC | Summary for Policymakers. In: Global Warming of 1.5°C. An IPCC Special Report on the impacts of global warming of 1.5°C above pre-industrial levels and related global greenhouse gas emission pathways, in the context of strengthening the global response to the threat of climate change, sustainable development, and efforts to eradicate poverty. | https://www.ipcc.ch/site/assets/uploads/sites/2/2022/06/SPM_version_report_LR.pdf | 24 | 2018
646
- IPCC | Summary for Policymakers. In: Climate Change and Land: an IPCC special report on climate change, desertification, land degradation, sustainable land management, food security, and greenhouse gas fluxes in terrestrial ecosystems. | https://www.ipcc.ch/site/assets/uploads/sites/4/2022/11/SRCCL_SPM.pdf | 36 | 2019
647
- IPCC | Summary for Policymakers. In: IPCC Special Report on the Ocean and Cryosphere in a Changing Climate. | https://www.ipcc.ch/site/assets/uploads/sites/3/2022/03/01_SROCC_SPM_FINAL.pdf | 36 | 2019
648
- IPCC | Technical Summary. In: IPCC Special Report on the Ocean and Cryosphere in a Changing Climate. | https://www.ipcc.ch/site/assets/uploads/sites/3/2022/03/02_SROCC_TS_FINAL.pdf | 34 | 2019
649
- IPCC | Chapter 1 - Framing and Context of the Report. In: IPCC Special Report on the Ocean and Cryosphere in a Changing Climate. | https://www.ipcc.ch/site/assets/uploads/sites/3/2022/03/03_SROCC_Ch01_FINAL.pdf | 60 | 2019
650
- IPCC | Chapter 2 - High Mountain Areas. In: IPCC Special Report on the Ocean and Cryosphere in a Changing Climate. | https://www.ipcc.ch/site/assets/uploads/sites/3/2022/03/04_SROCC_Ch02_FINAL.pdf | 72 | 2019
651
- IPCC | Chapter 3 - Polar Regions. In: IPCC Special Report on the Ocean and Cryosphere in a Changing Climate. | https://www.ipcc.ch/site/assets/uploads/sites/3/2022/03/05_SROCC_Ch03_FINAL.pdf | 118 | 2019
652
- IPCC | Chapter 4 - Sea Level Rise and Implications for Low-Lying Islands, Coasts and Communities. In: IPCC Special Report on the Ocean and Cryosphere in a Changing Climate. | https://www.ipcc.ch/site/assets/uploads/sites/3/2022/03/06_SROCC_Ch04_FINAL.pdf | 126 | 2019
653
- IPCC | Chapter 5 - Changing Ocean, Marine Ecosystems, and Dependent Communities. In: IPCC Special Report on the Ocean and Cryosphere in a Changing Climate. | https://www.ipcc.ch/site/assets/uploads/sites/3/2022/03/07_SROCC_Ch05_FINAL.pdf | 142 | 2019
654
- IPCC | Chapter 6 - Extremes, Abrupt Changes and Managing Risk. In: IPCC Special Report on the Ocean and Cryosphere in a Changing Climate. | https://www.ipcc.ch/site/assets/uploads/sites/3/2022/03/08_SROCC_Ch06_FINAL.pdf | 68 | 2019
655
- IPCC | Cross-Chapter Box 9: Integrative Cross-Chapter Box on Low-Lying Islands and Coasts. In: IPCC Special Report on the Ocean and Cryosphere in a Changing Climate. | https://www.ipcc.ch/site/assets/uploads/sites/3/2019/11/11_SROCC_CCB9-LLIC_FINAL.pdf | 18 | 2019
656
- IPCC | Annex I: Glossary [Weyer, N.M. (ed.)]. In: IPCC Special Report on the Ocean and Cryosphere in a Changing Climate. | https://www.ipcc.ch/site/assets/uploads/sites/3/2022/03/10_SROCC_AnnexI-Glossary_FINAL.pdf | 28 | 2019
657
- IPBES | Full Report. Global assessment report on biodiversity and ecosystem services of the IPBES. | https://zenodo.org/record/6417333/files/202206_IPBES%20GLOBAL%20REPORT_FULL_DIGITAL_MARCH%202022.pdf | 1148 | 2019
658
- IPBES | Summary for Policymakers. Global assessment report on biodiversity and ecosystem services of the IPBES (Version 1). | https://zenodo.org/record/3553579/files/ipbes_global_assessment_report_summary_for_policymakers.pdf | 60 | 2019
659
- IPBES | Full Report. Thematic assessment of the sustainable use of wild species of the IPBES. | https://zenodo.org/record/7755805/files/IPBES_ASSESSMENT_SUWS_FULL_REPORT.pdf | 1008 | 2022
660
- IPBES | Summary for Policymakers. Summary for policymakers of the thematic assessment of the sustainable use of wild species of the IPBES. | https://zenodo.org/record/7411847/files/EN_SPM_SUSTAINABLE%20USE%20OF%20WILD%20SPECIES.pdf | 44 | 2022
661
- IPBES | Full Report. Regional Assessment Report on Biodiversity and Ecosystem Services for Africa. | https://zenodo.org/record/3236178/files/ipbes_assessment_report_africa_EN.pdf | 494 | 2018
662
- IPBES | Summary for Policymakers. Regional Assessment Report on Biodiversity and Ecosystem Services for Africa. | https://zenodo.org/record/3236189/files/ipbes_assessment_spm_africa_EN.pdf | 52 | 2018
663
- IPBES | Full Report. Regional Assessment Report on Biodiversity and Ecosystem Services for the Americas. | https://zenodo.org/record/3236253/files/ipbes_assessment_report_americas_EN.pdf | 660 | 2018
664
- IPBES | Summary for Policymakers. Regional Assessment Report on Biodiversity and Ecosystem Services for the Americas. | https://zenodo.org/record/3236292/files/ipbes_assessment_spm_americas_EN.pdf | 44 | 2018
665
- IPBES | Full Report. Regional Assessment Report on Biodiversity and Ecosystem Services for Asia and the Pacific. | https://zenodo.org/record/3237374/files/ipbes_assessment_report_ap_EN.pdf | 616 | 2018
666
- IPBES | Summary for Policymakers. Regional Assessment Report on Biodiversity and Ecosystem Services for Asia and the Pacific. | https://zenodo.org/record/3237383/files/ipbes_assessment_spm_ap_EN.pdf | 44 | 2018
667
- IPBES | Full Report. Regional Assessment Report on Biodiversity and Ecosystem Services for Europe and Central Asia. | https://zenodo.org/record/3237429/files/ipbes_assessment_report_eca_EN.pdf | 894 | 2018
668
- IPBES | Summary for Policymakers. Regional Assessment Report on Biodiversity and Ecosystem Services for Europe and Central Asia. | https://zenodo.org/record/3237468/files/ipbes_assessment_spm_eca_EN.pdf | 52 | 2018
669
- IPBES | Full Report. Assessment Report on Land Degradation and Restoration. | https://zenodo.org/record/3237393/files/ipbes_assessment_report_ldra_EN.pdf | 748 | 2018
670
- IPBES | IPBES Invasive Alien Species Assessment: Summary for Policymakers & 6 chapters | https://zenodo.org/records/10127924/files/Summary%20for%20policymakers_IPBES%20IAS%20Assessment.pdf | 56 + 1198 | 2023
671
- """)
672
-
673
- with gr.Tab("Carbon Footprint",elem_classes = "max-height other-tabs"):
674
- gr.Markdown("""
675
-
676
- Carbon emissions were measured during the development and inference process using CodeCarbon [https://github.com/mlco2/codecarbon](https://github.com/mlco2/codecarbon)
677
-
678
- | Phase | Description | Emissions | Source |
679
- | --- | --- | --- | --- |
680
- | Development | OCR and parsing all pdf documents with AI | 28gCO2e | CodeCarbon |
681
- | Development | Question Answering development | 114gCO2e | CodeCarbon |
682
- | Inference | Question Answering | ~0.102gCO2e / call | CodeCarbon |
683
- | Inference | API call to turbo-GPT | ~0.38gCO2e / call | https://medium.com/@chrispointon/the-carbon-footprint-of-chatgpt-e1bc14e4cc2a |
684
-
685
- Carbon Emissions are **relatively low but not negligible** compared to other usages: one question asked to ClimateQ&A is around 0.482gCO2e - equivalent to 2.2m by car (https://datagir.ademe.fr/apps/impact-co2/)
686
- Or around 2 to 4 times more than a typical Google search.
687
- """
688
- )
689
-
690
- with gr.Tab("Changelog",elem_classes = "max-height other-tabs"):
691
- gr.Markdown("""
692
-
693
- ##### Upcoming features
694
- - Figures retrieval and multimodal system
695
- - Conversational chat
696
- - Intent routing
697
- - Local environment setup
698
-
699
- ##### v1.3.0-alpha - *2024-01-31*
700
- - Completely redesign chunking system mechanism at the parsing phase (hierarchical aggregations, better control to get 256 tokens)
701
- - Switched to Pinecone serverless for performance improvements
702
- - Add TOC section for each source in the citations panel as breadcrumbs
703
- - *EXPERIMENTAL* - Figure retrieval system within the answer (caption pictures with GPT4 Vision and indexing the caption in the retrieval system)
704
-
705
- ##### v1.2.1 - *2024-01-16*
706
- - *BUG* - corrected asynchronous bug failing the chatbot frequently
707
-
708
- ##### v1.2.0 - *2023-11-27*
709
- - Added new IPBES assessment on Invasive Species (SPM and chapters)
710
- - Switched all the codebase to LCEL (Langchain Expression Language)
711
- - Added sample questions by category
712
- - Switched embeddings from old ``sentence-transformers/multi-qa-mpnet-base-dot-v1`` to ``BAAI/bge-base-en-v1.5``
713
- - Report filtering to select directly the report you want to source your answers from
714
- - First naive version of a figures retrieval system by looking up the figures in the retrieved pages
715
-
716
- ##### v1.1.0 - *2023-10-16*
717
- - ClimateQ&A on Hugging Face is finally working again with all the new features !
718
- - Switched all python code to langchain codebase for cleaner code, easier maintenance and future features
719
- - Updated GPT model to August version
720
- - Added streaming response to improve UX
721
- - Created a custom Retriever chain to avoid calling the LLM if there is no documents retrieved
722
- - Use of HuggingFace embed on https://climateqa.com to avoid demultiplying deployments
723
-
724
- ##### v1.0.0 - *2023-05-11*
725
- - First version of clean interface on https://climateqa.com
726
- - Add children mode on https://climateqa.com
727
- - Add follow-up questions https://climateqa.com
728
- """
729
- )
730
-
731
-
732
 
733
 
734
  def start_chat(query,history):
735
- history = history + [(query,"")]
736
  history = [tuple(x) for x in history]
737
- print(history)
738
  return (gr.update(interactive = False),gr.update(selected=1),history)
739
 
740
  def finish_chat():
@@ -784,6 +579,24 @@ Or around 2 to 4 times more than a typical Google search.
784
  # )
785
 
786
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
787
  demo.queue()
788
 
789
  demo.launch()
 
10
  import re
11
  import json
12
 
13
+ from gradio_modal import Modal
14
+
15
  from io import BytesIO
16
  import base64
17
 
 
110
  return new_docs
111
 
112
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
113
 
114
  async def chat(query,history,audience,sources,reports):
115
  """taking a query and a message history, use a pipeline (reformulation, retriever, answering) to yield a tuple of:
116
  (messages in gradio format, messages in langchain format, source documents)"""
117
 
118
+ print(f">> NEW QUESTION : {query}")
119
+
120
  if audience == "Children":
121
  audience_prompt = audience_prompts["children"]
122
  elif audience == "General public":
 
176
 
177
  elif op['path'] == path_answer: # final answer
178
  new_token = op['value'] # str
179
+ # time.sleep(0.01)
180
+ previous_answer = history[-1][1]
181
+ previous_answer = previous_answer if previous_answer is not None else ""
182
+ answer_yet = previous_answer + new_token
183
  answer_yet = parse_output_llm_with_sources(answer_yet)
184
  history[-1] = (query,answer_yet)
185
 
 
313
  else:
314
  break
315
  toc_levels = " > ".join(toc_levels)
 
316
 
317
  if len(toc_levels) > 0:
318
  name = f"<b>{toc_levels}</b><br/>{meta['name']}"
319
  else:
320
  name = meta['name']
321
 
 
 
 
322
  if meta["chunk_type"] == "text":
323
 
324
  card = f"""
 
389
  def log_on_azure(file, logs, share_client):
390
  logs = json.dumps(logs)
391
  file_client = share_client.get_file_client(file)
 
 
 
 
392
  file_client.upload_file(logs)
 
393
 
394
 
395
  # --------------------------------------------------------------------
 
439
 
440
 
441
  with gr.Row(elem_id = "input-message"):
442
+ textbox=gr.Textbox(placeholder="Ask me anything here!",show_label=False,scale=7,lines = 1,interactive = True,elem_id="input-textbox")
443
+ # submit = gr.Button("",elem_id = "submit-button",scale = 1,interactive = True,icon = "https://static-00.iconduck.com/assets.00/settings-icon-2048x2046-cw28eevx.png")
444
 
445
 
446
  with gr.Column(scale=1, variant="panel",elem_id = "right-panel"):
 
478
  sources_textbox = gr.HTML(show_label=False, elem_id="sources-textbox")
479
  docs_textbox = gr.State("")
480
 
481
+ # with Modal(visible = False) as config_modal:
482
  with gr.Tab("Configuration",elem_id = "tab-config",id = 2):
483
 
484
  gr.Markdown("Reminder: You can talk in any language, ClimateQ&A is multi-lingual!")
485
 
486
 
487
  dropdown_sources = gr.CheckboxGroup(
488
+ ["IPCC", "IPBES","IPOS"],
489
  label="Select source",
490
  value=["IPCC"],
491
  interactive=True,
 
521
  with gr.Tab("Figures",elem_id = "tab-images",elem_classes = "max-height other-tabs"):
522
  gallery_component = gr.Gallery()
523
 
524
+ with gr.Tab("About",elem_classes = "max-height other-tabs"):
525
  with gr.Row():
526
  with gr.Column(scale=1):
527
+ gr.Markdown("See more info at [https://climateqa.com](https://climateqa.com/docs/intro/)")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
528
 
529
 
530
  def start_chat(query,history):
531
+ history = history + [(query,None)]
532
  history = [tuple(x) for x in history]
 
533
  return (gr.update(interactive = False),gr.update(selected=1),history)
534
 
535
  def finish_chat():
 
579
  # )
580
 
581
 
582
+ # with Modal(visible=True) as first_modal:
583
+ # gr.Markdown("# Welcome to ClimateQ&A !")
584
+
585
+ # gr.Markdown("### Examples")
586
+
587
+ # examples = gr.Examples(
588
+ # ["Yo Γ§a roule","Γ§a boume"],
589
+ # [examples_hidden],
590
+ # examples_per_page=8,
591
+ # run_on_click=False,
592
+ # elem_id="examples",
593
+ # api_name="examples",
594
+ # )
595
+
596
+
597
+ # submit.click(lambda: Modal(visible=True), None, config_modal)
598
+
599
+
600
  demo.queue()
601
 
602
  demo.launch()
climateqa/engine/retriever.py CHANGED
@@ -13,7 +13,7 @@ from pydantic import Field
13
 
14
  class ClimateQARetriever(BaseRetriever):
15
  vectorstore:VectorStore
16
- sources:list = ["IPCC","IPBES"]
17
  reports:list = []
18
  threshold:float = 0.6
19
  k_summary:int = 3
@@ -28,7 +28,7 @@ class ClimateQARetriever(BaseRetriever):
28
 
29
  # Check if all elements in the list are either IPCC or IPBES
30
  assert isinstance(self.sources,list)
31
- assert all([x in ["IPCC","IPBES"] for x in self.sources])
32
  assert self.k_total > self.k_summary, "k_total should be greater than k_summary"
33
 
34
  # Prepare base search kwargs
@@ -60,7 +60,8 @@ class ClimateQARetriever(BaseRetriever):
60
  docs = docs_summaries + docs_full
61
 
62
  # Filter if scores are below threshold
63
- # docs = [x for x in docs if x[1] > self.threshold and len(x[0].page_content) > self.min_size]
 
64
 
65
  # Add score to metadata
66
  results = []
 
13
 
14
  class ClimateQARetriever(BaseRetriever):
15
  vectorstore:VectorStore
16
+ sources:list = ["IPCC","IPBES","IPOS"]
17
  reports:list = []
18
  threshold:float = 0.6
19
  k_summary:int = 3
 
28
 
29
  # Check if all elements in the list are either IPCC or IPBES
30
  assert isinstance(self.sources,list)
31
+ assert all([x in ["IPCC","IPBES","IPOS"] for x in self.sources])
32
  assert self.k_total > self.k_summary, "k_total should be greater than k_summary"
33
 
34
  # Prepare base search kwargs
 
60
  docs = docs_summaries + docs_full
61
 
62
  # Filter if scores are below threshold
63
+ docs = [x for x in docs if len(x[0].page_content) > self.min_size]
64
+ # docs = [x for x in docs if x[1] > self.threshold]
65
 
66
  # Add score to metadata
67
  results = []
climateqa/sample_questions.py CHANGED
@@ -80,6 +80,25 @@ QUESTIONS = {
80
  "What is the distribution of uncertainty in projected precipitation changes across different time frames ?",
81
  "What are the anticipated changes in the global water cycle by the end of the 21st century under an intermediate emissions scenario ?",
82
  "How are human activities contributing to the spread of invasive alien species?",
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
83
  ]
84
-
85
  }
 
80
  "What is the distribution of uncertainty in projected precipitation changes across different time frames ?",
81
  "What are the anticipated changes in the global water cycle by the end of the 21st century under an intermediate emissions scenario ?",
82
  "How are human activities contributing to the spread of invasive alien species?",
83
+ ],
84
+ "Deep Sea Mining":[
85
+ "What is the motivation behind mining the deep seabed?",
86
+ "What are the arguments in favor of and against deep-sea mining?",
87
+ "Can the global demand for metals and resources be met adequately through land-based sources for the next few decades?",
88
+ "Is it essential for humanity to exploit the deep ocean for minerals, or should we consider alternative pathways?",
89
+ "What are the environmental impacts of deep-sea mining in order of significance, indicating the degree or severity of the impacts?",
90
+ "What specific substances are likely to be released as contaminants through deep-sea mining?",
91
+ "How might the substances released through deep-sea mining pose a threat to marine life?",
92
+ "What are the various environmental stressors associated with deep-sea mining, including factors like noise, vibration, and light?",
93
+ "How would environmental stressors associated with deep-sea mining affect marine ecosystems?",
94
+ "How will the removal of mineral resources as a result of deep-sea mining impact the living components of the ecosystem?",
95
+ "How will deep-sea mining influence ocean currents, large-scale circulation, and biogeochemical cycles?",
96
+ "What are the potential ramifications of deep-sea mining for global ocean processes?",
97
+ "What are the potential repercussions of deep-sea mining on climate regulation, considering the role of deep-sea ecosystems in climate dynamics?",
98
+ "How resilient are the targeted habitats of deep-sea ecosystems (nodules, sulfides, crusts) to the impacts of deep-sea mining?",
99
+ "Apart from the ecological consequences of deep-sea mining, what economic challenges could a state encounter if a deep-seabed mining operation leads to financial losses or third-party liability?",
100
+ "What legal steps would need to be designed to authorize deep-sea mining?",
101
+ "Is the current technological infrastructure sufficiently advanced and tested to support the implementation of deep-sea mining operations effectively?",
102
+ "Provide me with a list of organizations most actively opposing deep-sea mining."
103
  ]
 
104
  }
requirements.txt CHANGED
@@ -1,4 +1,4 @@
1
- gradio==4.2.0
2
  azure-storage-file-share==12.11.1
3
  azure-storage-blob
4
  python-dotenv==1.0.0
 
1
+ gradio==4.19.1
2
  azure-storage-file-share==12.11.1
3
  azure-storage-blob
4
  python-dotenv==1.0.0
style.css CHANGED
@@ -319,4 +319,43 @@ span.chatbot > p > img{
319
 
320
  .card-image > .card-content{
321
  background-color:#f1f7fa !important;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
322
  }
 
319
 
320
  .card-image > .card-content{
321
  background-color:#f1f7fa !important;
322
+ }
323
+
324
+
325
+
326
+ .tab-nav > button.selected{
327
+ color:#4b8ec3;
328
+ font-weight:bold;
329
+ border:none;
330
+ }
331
+
332
+ .tab-nav{
333
+ border:none !important;
334
+ }
335
+
336
+ #input-textbox > label > textarea{
337
+ border-radius:40px;
338
+ padding-left:30px;
339
+ resize:none;
340
+ }
341
+
342
+ #input-message > div{
343
+ border:none;
344
+ }
345
+
346
+ #dropdown-samples{
347
+ /*! border:none !important; */
348
+ /*! border-width:0px !important; */
349
+ background:none !important;
350
+
351
+ }
352
+
353
+ #dropdown-samples > .container > .wrap{
354
+ background-color:white;
355
+ }
356
+
357
+
358
+ #tab-examples > div > .form{
359
+ border:none;
360
+ background:none !important;
361
  }