Spaces:
Runtime error
Runtime error
LOUIS SANNA
commited on
Commit
•
528bf3d
1
Parent(s):
d6936f0
feat(source): add table
Browse files- anyqa/build_index.py +2 -3
- anyqa/source_table.py +43 -0
- app.py +7 -46
anyqa/build_index.py
CHANGED
@@ -59,9 +59,8 @@ def parse_domain(source: str) -> str:
|
|
59 |
|
60 |
|
61 |
def clear_index():
|
62 |
-
|
63 |
-
|
64 |
-
file_path = os.path.join(folder, filename)
|
65 |
try:
|
66 |
if os.path.isfile(file_path) or os.path.islink(file_path):
|
67 |
os.unlink(file_path)
|
|
|
59 |
|
60 |
|
61 |
def clear_index():
|
62 |
+
for filename in os.listdir("../chroma_db"):
|
63 |
+
file_path = os.path.join("../chroma_db", filename)
|
|
|
64 |
try:
|
65 |
if os.path.isfile(file_path) or os.path.islink(file_path):
|
66 |
os.unlink(file_path)
|
anyqa/source_table.py
ADDED
@@ -0,0 +1,43 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
config_list = [
|
2 |
+
{
|
3 |
+
"type": "Doism",
|
4 |
+
"source": "Tao Te Ching",
|
5 |
+
"URL": "https://www.with.org/tao_te_ching_en.pdf",
|
6 |
+
},
|
7 |
+
{
|
8 |
+
"type": "Confucianism",
|
9 |
+
"source": "The Analects of Confucius",
|
10 |
+
"URL": "https://chinatxt.sitehost.iu.edu/Analects_of_Confucius_(Eno-2015).pdf",
|
11 |
+
},
|
12 |
+
# Add more dictionaries as needed
|
13 |
+
]
|
14 |
+
|
15 |
+
|
16 |
+
def generate_source_table():
|
17 |
+
# Define the headers for the table
|
18 |
+
headers = ["Type", "Name", "URL"]
|
19 |
+
|
20 |
+
# Create the Markdown string for the headers
|
21 |
+
header_str = " | ".join(headers)
|
22 |
+
|
23 |
+
# Create the Markdown string for the header separator
|
24 |
+
separator_str = " | ".join(["---"] * len(headers))
|
25 |
+
|
26 |
+
# Initialize an empty list to hold the rows
|
27 |
+
rows = []
|
28 |
+
|
29 |
+
# Add each row to the list
|
30 |
+
for config in config_list:
|
31 |
+
row = [
|
32 |
+
config.get("type", ""),
|
33 |
+
config.get("source", ""),
|
34 |
+
config.get("URL", ""),
|
35 |
+
]
|
36 |
+
|
37 |
+
row_str = " | ".join(row)
|
38 |
+
rows.append(row_str)
|
39 |
+
|
40 |
+
# Combine all the parts into the final Markdown table
|
41 |
+
markdown_table = header_str + "\n" + separator_str + "\n" + "\n".join(rows)
|
42 |
+
|
43 |
+
return markdown_table
|
app.py
CHANGED
@@ -8,14 +8,14 @@ from langchain.callbacks.streaming_stdout import StreamingStdOutCallbackHandler
|
|
8 |
|
9 |
# ClimateQ&A imports
|
10 |
from anyqa.config import get_domains
|
|
|
11 |
from anyqa.embeddings import EMBEDDING_MODEL_NAME
|
12 |
from anyqa.llm import get_llm
|
|
|
13 |
from anyqa.qa_logging import log
|
14 |
-
from anyqa.chains import load_qa_chain_with_text
|
15 |
-
from anyqa.chains import load_reformulation_chain
|
16 |
-
from anyqa.vectorstore import get_vectorstore
|
17 |
from anyqa.retriever import QARetriever
|
18 |
-
from anyqa.
|
|
|
19 |
|
20 |
# Load environment variables in local mode
|
21 |
try:
|
@@ -138,7 +138,6 @@ def answer_user_example(query, query_example, history):
|
|
138 |
|
139 |
|
140 |
def fetch_sources(query, domains):
|
141 |
-
|
142 |
llm_reformulation = get_llm(
|
143 |
max_tokens=512, temperature=0.0, verbose=True, streaming=False
|
144 |
)
|
@@ -529,47 +528,7 @@ with gr.Blocks(title="❓ Q&A", css="style.css", theme=theme) as demo:
|
|
529 |
)
|
530 |
|
531 |
with gr.Tab("📚 Sources", elem_classes="max-height"):
|
532 |
-
gr.Markdown(
|
533 |
-
"""
|
534 |
-
| Source | Report | URL | Number of pages | Release date |
|
535 |
-
| --- | --- | --- | --- | --- |
|
536 |
-
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
|
537 |
-
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
|
538 |
-
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
|
539 |
-
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
|
540 |
-
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
|
541 |
-
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
|
542 |
-
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
|
543 |
-
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
|
544 |
-
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
|
545 |
-
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
|
546 |
-
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
|
547 |
-
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
|
548 |
-
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
|
549 |
-
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
|
550 |
-
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
|
551 |
-
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
|
552 |
-
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
|
553 |
-
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
|
554 |
-
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
|
555 |
-
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
|
556 |
-
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
|
557 |
-
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
|
558 |
-
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
|
559 |
-
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
|
560 |
-
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
|
561 |
-
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
|
562 |
-
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
|
563 |
-
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
|
564 |
-
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
|
565 |
-
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
|
566 |
-
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
|
567 |
-
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
|
568 |
-
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
|
569 |
-
IPBES | Full Report. Assessment Report on Land Degradation and Restoration. | https://zenodo.org/record/3237393/files/ipbes_assessment_report_ldra_EN.pdf | 748 | 2018
|
570 |
-
IPBES | Summary for Policymakers. Assessment Report on Land Degradation and Restoration. | https://zenodo.org/record/3237393/files/ipbes_assessment_report_ldra_EN.pdf | 48 | 2018
|
571 |
-
"""
|
572 |
-
)
|
573 |
|
574 |
with gr.Tab("🛢️ Carbon Footprint"):
|
575 |
gr.Markdown(
|
@@ -605,3 +564,5 @@ Or around 2 to 4 times more than a typical Google search.
|
|
605 |
demo.queue(concurrency_count=16)
|
606 |
|
607 |
demo.launch()
|
|
|
|
|
|
8 |
|
9 |
# ClimateQ&A imports
|
10 |
from anyqa.config import get_domains
|
11 |
+
from anyqa.chains import load_qa_chain_with_text, load_reformulation_chain
|
12 |
from anyqa.embeddings import EMBEDDING_MODEL_NAME
|
13 |
from anyqa.llm import get_llm
|
14 |
+
from anyqa.prompts import audience_prompts
|
15 |
from anyqa.qa_logging import log
|
|
|
|
|
|
|
16 |
from anyqa.retriever import QARetriever
|
17 |
+
from anyqa.source_table import generate_source_table
|
18 |
+
from anyqa.vectorstore import get_vectorstore
|
19 |
|
20 |
# Load environment variables in local mode
|
21 |
try:
|
|
|
138 |
|
139 |
|
140 |
def fetch_sources(query, domains):
|
|
|
141 |
llm_reformulation = get_llm(
|
142 |
max_tokens=512, temperature=0.0, verbose=True, streaming=False
|
143 |
)
|
|
|
528 |
)
|
529 |
|
530 |
with gr.Tab("📚 Sources", elem_classes="max-height"):
|
531 |
+
gr.Markdown(generate_source_table())
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
532 |
|
533 |
with gr.Tab("🛢️ Carbon Footprint"):
|
534 |
gr.Markdown(
|
|
|
564 |
demo.queue(concurrency_count=16)
|
565 |
|
566 |
demo.launch()
|
567 |
+
|
568 |
+
|