Commit
·
8293c85
1
Parent(s):
d0ac130
feat: added plot informations for each plot (DRIAS & IPCC)
Browse files- climateqa/engine/talk_to_data/drias/plot_informations.py +88 -0
- climateqa/engine/talk_to_data/drias/plots.py +5 -0
- climateqa/engine/talk_to_data/ipcc/plot_informations.py +50 -0
- climateqa/engine/talk_to_data/ipcc/plots.py +4 -1
- climateqa/engine/talk_to_data/main.py +21 -11
- climateqa/engine/talk_to_data/objects/plot.py +1 -0
- climateqa/engine/talk_to_data/objects/states.py +1 -0
- climateqa/engine/talk_to_data/workflow/drias.py +5 -1
- climateqa/engine/talk_to_data/workflow/ipcc.py +5 -1
- front/tabs/tab_drias.py +12 -3
- front/tabs/tab_ipcc.py +15 -4
climateqa/engine/talk_to_data/drias/plot_informations.py
ADDED
|
@@ -0,0 +1,88 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from climateqa.engine.talk_to_data.drias.config import DRIAS_INDICATOR_TO_UNIT
|
| 2 |
+
|
| 3 |
+
def indicator_evolution_informations(
|
| 4 |
+
indicator: str,
|
| 5 |
+
params: dict[str, str]
|
| 6 |
+
) -> str:
|
| 7 |
+
unit = DRIAS_INDICATOR_TO_UNIT[indicator]
|
| 8 |
+
if "location" not in params:
|
| 9 |
+
raise ValueError('"location" must be provided in params')
|
| 10 |
+
location = params["location"]
|
| 11 |
+
return f"""
|
| 12 |
+
This plot shows how the climate indicator **{indicator}** evolves over time in **{location}**.
|
| 13 |
+
|
| 14 |
+
It combines both historical observations and future projections according to the climate scenario RCP8.5.
|
| 15 |
+
|
| 16 |
+
The x-axis represents the years, and the y-axis shows the value of the indicator ({unit}).
|
| 17 |
+
|
| 18 |
+
A 10-year rolling average curve is displayed to give a better idea of the overall trend.
|
| 19 |
+
|
| 20 |
+
**Data source:**
|
| 21 |
+
- The data come from the DRIAS TRACC data. The data were initially extracted from [the DRIAS website](https://www.drias-climat.fr/drias_prod/accueil/okapiWebDrias/index.jsp?iddrias=climat) and then preprocessed to a tabular format and uploaded as parquet in this [Hugging Face dataset](https://huggingface.co/datasets/timeki/drias_db).
|
| 22 |
+
- For each year and climate model, the value of {indicator} in {location} is collected, to build the time series.
|
| 23 |
+
- The coordinates used for {location} correspond to the closest available point in the DRIAS database, which uses a regular grid with a spatial resolution of 8 km.
|
| 24 |
+
- The indicator values shown are those for the selected climate model.
|
| 25 |
+
- If ALL climate model is selected, the average value of the indicator between all the climate models is used.
|
| 26 |
+
"""
|
| 27 |
+
|
| 28 |
+
def indicator_number_of_days_per_year_informations(
|
| 29 |
+
indicator: str,
|
| 30 |
+
params: dict[str, str]
|
| 31 |
+
) -> str:
|
| 32 |
+
unit = DRIAS_INDICATOR_TO_UNIT[indicator]
|
| 33 |
+
if "location" not in params:
|
| 34 |
+
raise ValueError('"location" must be provided in params')
|
| 35 |
+
location = params["location"]
|
| 36 |
+
return f"""
|
| 37 |
+
This plot displays a bar chart showing the yearly frequency of the climate indicator **{indicator}** in **{location}**.
|
| 38 |
+
|
| 39 |
+
The x-axis represents the years, and the y-axis shows the frequency of {indicator} ({unit}) per year.
|
| 40 |
+
|
| 41 |
+
**Data source:**
|
| 42 |
+
- The data come from the DRIAS TRACC data. The data were initially extracted from [the DRIAS website](https://www.drias-climat.fr/drias_prod/accueil/okapiWebDrias/index.jsp?iddrias=climat) and then preprocessed to a tabular format and uploaded as parquet in this [Hugging Face dataset](https://huggingface.co/datasets/timeki/drias_db).
|
| 43 |
+
- For each year and climate model, the value of {indicator} in {location} is collected, to build the time series.
|
| 44 |
+
- The coordinates used for {location} correspond to the closest available point in the DRIAS database, which uses a regular grid with a spatial resolution of 8 km.
|
| 45 |
+
- The indicator values shown are those for the selected climate model.
|
| 46 |
+
- If ALL climate model is selected, the average value of the indicator between all the climate models is used.
|
| 47 |
+
"""
|
| 48 |
+
|
| 49 |
+
def distribution_of_indicator_for_given_year_informations(
|
| 50 |
+
indicator: str,
|
| 51 |
+
params: dict[str, str]
|
| 52 |
+
) -> str:
|
| 53 |
+
unit = DRIAS_INDICATOR_TO_UNIT[indicator]
|
| 54 |
+
year = params["year"]
|
| 55 |
+
if year is None:
|
| 56 |
+
year = 2030
|
| 57 |
+
return f"""
|
| 58 |
+
This plot shows a histogram of the distribution of the climate indicator **{indicator}** across all locations for the year **{year}**.
|
| 59 |
+
|
| 60 |
+
It allows you to visualize how the values of {indicator} ({unit}) are spread for a given year.
|
| 61 |
+
|
| 62 |
+
**Data source:**
|
| 63 |
+
- The data come from the DRIAS TRACC data. The data were initially extracted from [the DRIAS website](https://www.drias-climat.fr/drias_prod/accueil/okapiWebDrias/index.jsp?iddrias=climat) and then preprocessed to a tabular format and uploaded as parquet in this [Hugging Face dataset](https://huggingface.co/datasets/timeki/drias_db).
|
| 64 |
+
- For each grid point in the dataset and climate model, the value of {indicator} for the year {year} is extracted.
|
| 65 |
+
- The indicator values shown are those for the selected climate model.
|
| 66 |
+
- If ALL climate model is selected, the average value of the indicator between all the climate models is used.
|
| 67 |
+
"""
|
| 68 |
+
|
| 69 |
+
def map_of_france_of_indicator_for_given_year_informations(
|
| 70 |
+
indicator: str,
|
| 71 |
+
params: dict[str, str]
|
| 72 |
+
) -> str:
|
| 73 |
+
unit = DRIAS_INDICATOR_TO_UNIT[indicator]
|
| 74 |
+
year = params["year"]
|
| 75 |
+
if year is None:
|
| 76 |
+
year = 2030
|
| 77 |
+
return f"""
|
| 78 |
+
This plot displays a choropleth map showing the spatial distribution of **{indicator}** across all regions of France for the year **{year}**.
|
| 79 |
+
|
| 80 |
+
Each region is colored according to the value of the indicator ({unit}), allowing you to visually compare how {indicator} varies geographically within France for the selected year and climate model.
|
| 81 |
+
|
| 82 |
+
**Data source:**
|
| 83 |
+
- The data come from the DRIAS TRACC data. The data were initially extracted from [the DRIAS website](https://www.drias-climat.fr/drias_prod/accueil/okapiWebDrias/index.jsp?iddrias=climat) and then preprocessed to a tabular format and uploaded as parquet in this [Hugging Face dataset](https://huggingface.co/datasets/timeki/drias_db).
|
| 84 |
+
- For each region of France, the value of {indicator} in {year} and for the selected climate model is extracted and mapped to its geographic coordinates.
|
| 85 |
+
- The regions correspond to 8 km squares centered on the grid points of the DRIAS dataset.
|
| 86 |
+
- The indicator values shown are those for the selected climate model.
|
| 87 |
+
- If ALL climate model is selected, the average value of the indicator between all the climate models is used.
|
| 88 |
+
"""
|
climateqa/engine/talk_to_data/drias/plots.py
CHANGED
|
@@ -5,6 +5,7 @@ from typing import Callable
|
|
| 5 |
import pandas as pd
|
| 6 |
from plotly.graph_objects import Figure
|
| 7 |
import plotly.graph_objects as go
|
|
|
|
| 8 |
from climateqa.engine.talk_to_data.objects.plot import Plot
|
| 9 |
from climateqa.engine.talk_to_data.drias.queries import (
|
| 10 |
indicator_for_given_year_query,
|
|
@@ -162,6 +163,7 @@ indicator_evolution_at_location: Plot = {
|
|
| 162 |
"params": ["indicator_column", "location", "model"],
|
| 163 |
"plot_function": plot_indicator_evolution_at_location,
|
| 164 |
"sql_query": indicator_per_year_at_location_query,
|
|
|
|
| 165 |
'short_name': 'Indicator Evolution'
|
| 166 |
}
|
| 167 |
|
|
@@ -246,6 +248,7 @@ indicator_number_of_days_per_year_at_location: Plot = {
|
|
| 246 |
"params": ["indicator_column", "location", "model"],
|
| 247 |
"plot_function": plot_indicator_number_of_days_per_year_at_location,
|
| 248 |
"sql_query": indicator_per_year_at_location_query,
|
|
|
|
| 249 |
"short_name": "Indicator Yearly Frequency",
|
| 250 |
}
|
| 251 |
|
|
@@ -331,6 +334,7 @@ distribution_of_indicator_for_given_year: Plot = {
|
|
| 331 |
"params": ["indicator_column", "model", "year"],
|
| 332 |
"plot_function": plot_distribution_of_indicator_for_given_year,
|
| 333 |
"sql_query": indicator_for_given_year_query,
|
|
|
|
| 334 |
'short_name': 'Indicator Distribution'
|
| 335 |
}
|
| 336 |
|
|
@@ -418,6 +422,7 @@ map_of_france_of_indicator_for_given_year: Plot = {
|
|
| 418 |
"params": ["indicator_column", "year", "model"],
|
| 419 |
"plot_function": plot_map_of_france_of_indicator_for_given_year,
|
| 420 |
"sql_query": indicator_for_given_year_query,
|
|
|
|
| 421 |
'short_name': 'Map of France'
|
| 422 |
}
|
| 423 |
|
|
|
|
| 5 |
import pandas as pd
|
| 6 |
from plotly.graph_objects import Figure
|
| 7 |
import plotly.graph_objects as go
|
| 8 |
+
from climateqa.engine.talk_to_data.drias.plot_informations import distribution_of_indicator_for_given_year_informations, indicator_evolution_informations, indicator_number_of_days_per_year_informations, map_of_france_of_indicator_for_given_year_informations
|
| 9 |
from climateqa.engine.talk_to_data.objects.plot import Plot
|
| 10 |
from climateqa.engine.talk_to_data.drias.queries import (
|
| 11 |
indicator_for_given_year_query,
|
|
|
|
| 163 |
"params": ["indicator_column", "location", "model"],
|
| 164 |
"plot_function": plot_indicator_evolution_at_location,
|
| 165 |
"sql_query": indicator_per_year_at_location_query,
|
| 166 |
+
"plot_information": indicator_evolution_informations,
|
| 167 |
'short_name': 'Indicator Evolution'
|
| 168 |
}
|
| 169 |
|
|
|
|
| 248 |
"params": ["indicator_column", "location", "model"],
|
| 249 |
"plot_function": plot_indicator_number_of_days_per_year_at_location,
|
| 250 |
"sql_query": indicator_per_year_at_location_query,
|
| 251 |
+
"plot_information": indicator_number_of_days_per_year_informations,
|
| 252 |
"short_name": "Indicator Yearly Frequency",
|
| 253 |
}
|
| 254 |
|
|
|
|
| 334 |
"params": ["indicator_column", "model", "year"],
|
| 335 |
"plot_function": plot_distribution_of_indicator_for_given_year,
|
| 336 |
"sql_query": indicator_for_given_year_query,
|
| 337 |
+
"plot_information": distribution_of_indicator_for_given_year_informations,
|
| 338 |
'short_name': 'Indicator Distribution'
|
| 339 |
}
|
| 340 |
|
|
|
|
| 422 |
"params": ["indicator_column", "year", "model"],
|
| 423 |
"plot_function": plot_map_of_france_of_indicator_for_given_year,
|
| 424 |
"sql_query": indicator_for_given_year_query,
|
| 425 |
+
"plot_information": map_of_france_of_indicator_for_given_year_informations,
|
| 426 |
'short_name': 'Map of France'
|
| 427 |
}
|
| 428 |
|
climateqa/engine/talk_to_data/ipcc/plot_informations.py
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from climateqa.engine.talk_to_data.ipcc.config import IPCC_INDICATOR_TO_UNIT
|
| 2 |
+
|
| 3 |
+
def indicator_evolution_informations(
|
| 4 |
+
indicator: str,
|
| 5 |
+
params: dict[str,str],
|
| 6 |
+
) -> str:
|
| 7 |
+
if "location" not in params:
|
| 8 |
+
raise ValueError('"location" must be provided in params')
|
| 9 |
+
location = params["location"]
|
| 10 |
+
|
| 11 |
+
unit = IPCC_INDICATOR_TO_UNIT[indicator]
|
| 12 |
+
return f"""
|
| 13 |
+
This plot shows how the climate indicator **{indicator}** evolves over time in **{location}**.
|
| 14 |
+
|
| 15 |
+
It combines both historical (from 1950 to 2015) observations and future (from 2016 to 2100) projections for the different SSP climate scenarios (SSP126, SSP245, SSP370 and SSP585).
|
| 16 |
+
|
| 17 |
+
The x-axis represents the years (from 1950 to 2100), and the y-axis shows the value of the {indicator} ({unit}).
|
| 18 |
+
|
| 19 |
+
Each line corresponds to a different scenario, allowing you to compare how {indicator} might change under various future conditions.
|
| 20 |
+
|
| 21 |
+
**Data source:**
|
| 22 |
+
- The data comes from the CMIP6 IPCC ATLAS data. The data were initially extracted from [this referenced website](https://digital.csic.es/handle/10261/332744) and then preprocessed to a tabular format and uploaded as parquet in this [Hugging Face dataset](https://huggingface.co/datasets/Ekimetrics/ipcc-atlas).
|
| 23 |
+
- The underlying data is retrieved by aggregating yearly values of {indicator} for the selected location, across all available scenarios. This means the system collects, for each year, the value of {indicator} in {location}, both for the historical period and for each scenario, to build the time series.
|
| 24 |
+
- The coordinates used for {location} correspond to the closest available point in the IPCC database, which uses a regular grid with a spatial resolution of 1 degree.
|
| 25 |
+
"""
|
| 26 |
+
|
| 27 |
+
def choropleth_map_informations(
|
| 28 |
+
indicator: str,
|
| 29 |
+
params: dict[str, str],
|
| 30 |
+
) -> str:
|
| 31 |
+
unit = IPCC_INDICATOR_TO_UNIT[indicator]
|
| 32 |
+
if "location" not in params:
|
| 33 |
+
raise ValueError('"location" must be provided in params')
|
| 34 |
+
location = params["location"]
|
| 35 |
+
country_name = params["country_name"]
|
| 36 |
+
year = params["year"]
|
| 37 |
+
if year is None:
|
| 38 |
+
year = 2050
|
| 39 |
+
|
| 40 |
+
return f"""
|
| 41 |
+
This plot displays a choropleth map showing the spatial distribution of **{indicator}** across all regions of **{location}** country ({country_name}) for the year **{year}** and the chosen scenario.
|
| 42 |
+
|
| 43 |
+
Each region is colored according to the value of the indicator ({unit}), allowing you to visually compare how {indicator} varies geographically within the country for the selected year and scenario.
|
| 44 |
+
|
| 45 |
+
**Data source:**
|
| 46 |
+
- The data come from the CMIP6 IPCC ATLAS data. The data were initially extracted from [this referenced website](https://digital.csic.es/handle/10261/332744) and then preprocessed to a tabular format and uploaded as parquet in this [Hugging Face dataset](https://huggingface.co/datasets/Ekimetrics/ipcc-atlas).
|
| 47 |
+
- For each region of {location} country ({country_name}), the value of {indicator} in {year} and for the selected scenario is extracted and mapped to its geographic coordinates.
|
| 48 |
+
- The regions correspond to 1-degree squares centered on the grid points of the IPCC dataset.
|
| 49 |
+
- The coordinates used for each region are those of the closest available grid point in the IPCC database, which uses a regular grid with a spatial resolution of 1 degree.
|
| 50 |
+
"""
|
climateqa/engine/talk_to_data/ipcc/plots.py
CHANGED
|
@@ -5,6 +5,7 @@ import pandas as pd
|
|
| 5 |
import geojson
|
| 6 |
|
| 7 |
from climateqa.engine.talk_to_data.ipcc.config import IPCC_INDICATOR_TO_COLORSCALE, IPCC_INDICATOR_TO_UNIT, IPCC_SCENARIO
|
|
|
|
| 8 |
from climateqa.engine.talk_to_data.ipcc.queries import indicator_for_given_year_query, indicator_per_year_at_location_query
|
| 9 |
from climateqa.engine.talk_to_data.objects.plot import Plot
|
| 10 |
|
|
@@ -97,6 +98,7 @@ indicator_evolution_at_location_historical_and_projections: Plot = {
|
|
| 97 |
"params": ["indicator_column", "location"],
|
| 98 |
"plot_function": plot_indicator_evolution_at_location_historical_and_projections,
|
| 99 |
"sql_query": indicator_per_year_at_location_query,
|
|
|
|
| 100 |
"short_name": "Indicator Evolution"
|
| 101 |
}
|
| 102 |
|
|
@@ -177,7 +179,8 @@ choropleth_map_of_country_indicator_for_specific_year: Plot = {
|
|
| 177 |
"params": ["indicator_column", "year", "location"],
|
| 178 |
"plot_function": plot_choropleth_map_of_country_indicator_for_specific_year,
|
| 179 |
"sql_query": indicator_for_given_year_query,
|
| 180 |
-
"
|
|
|
|
| 181 |
}
|
| 182 |
|
| 183 |
IPCC_PLOTS = [
|
|
|
|
| 5 |
import geojson
|
| 6 |
|
| 7 |
from climateqa.engine.talk_to_data.ipcc.config import IPCC_INDICATOR_TO_COLORSCALE, IPCC_INDICATOR_TO_UNIT, IPCC_SCENARIO
|
| 8 |
+
from climateqa.engine.talk_to_data.ipcc.plot_informations import choropleth_map_informations, indicator_evolution_informations
|
| 9 |
from climateqa.engine.talk_to_data.ipcc.queries import indicator_for_given_year_query, indicator_per_year_at_location_query
|
| 10 |
from climateqa.engine.talk_to_data.objects.plot import Plot
|
| 11 |
|
|
|
|
| 98 |
"params": ["indicator_column", "location"],
|
| 99 |
"plot_function": plot_indicator_evolution_at_location_historical_and_projections,
|
| 100 |
"sql_query": indicator_per_year_at_location_query,
|
| 101 |
+
"plot_information": indicator_evolution_informations,
|
| 102 |
"short_name": "Indicator Evolution"
|
| 103 |
}
|
| 104 |
|
|
|
|
| 179 |
"params": ["indicator_column", "year", "location"],
|
| 180 |
"plot_function": plot_choropleth_map_of_country_indicator_for_specific_year,
|
| 181 |
"sql_query": indicator_for_given_year_query,
|
| 182 |
+
"plot_information": choropleth_map_informations,
|
| 183 |
+
"short_name": "Choropleth Map",
|
| 184 |
}
|
| 185 |
|
| 186 |
IPCC_PLOTS = [
|
climateqa/engine/talk_to_data/main.py
CHANGED
|
@@ -5,7 +5,6 @@ from climateqa.engine.llm import get_llm
|
|
| 5 |
from climateqa.engine.talk_to_data.workflow.ipcc import ipcc_workflow
|
| 6 |
from climateqa.logging import log_drias_interaction_to_huggingface
|
| 7 |
from climateqa.logging import log_drias_interaction_to_huggingface
|
| 8 |
-
import ast
|
| 9 |
|
| 10 |
async def ask_drias(query: str, index_state: int = 0, user_id: str | None = None) -> tuple:
|
| 11 |
"""Main function to process a DRIAS query and return results.
|
|
@@ -35,12 +34,16 @@ async def ask_drias(query: str, index_state: int = 0, user_id: str | None = None
|
|
| 35 |
result_dataframes = []
|
| 36 |
figures = []
|
| 37 |
plot_title_list = []
|
| 38 |
-
|
| 39 |
|
| 40 |
for output_title, output in final_state['outputs'].items():
|
| 41 |
if output['status'] == 'OK':
|
| 42 |
if output['table'] is not None:
|
| 43 |
plot_title_list.append(output_title)
|
|
|
|
|
|
|
|
|
|
|
|
|
| 44 |
if output['sql_query'] is not None:
|
| 45 |
sql_queries.append(output['sql_query'])
|
| 46 |
|
|
@@ -50,17 +53,19 @@ async def ask_drias(query: str, index_state: int = 0, user_id: str | None = None
|
|
| 50 |
figures.append(output['figure'])
|
| 51 |
|
| 52 |
if "error" in final_state and final_state["error"] != "":
|
| 53 |
-
# No Sql query, no dataframe, no figure, empty sql queries list, empty result dataframes list, empty figures list, index state = 0, empty table list, error message
|
| 54 |
-
return None, None, None, [], [], [], 0, [], final_state["error"]
|
| 55 |
|
| 56 |
sql_query = sql_queries[index_state]
|
| 57 |
dataframe = result_dataframes[index_state]
|
| 58 |
-
figure = figures[index_state](dataframe)
|
|
|
|
| 59 |
|
| 60 |
|
| 61 |
log_drias_interaction_to_huggingface(query, sql_query, user_id)
|
| 62 |
|
| 63 |
-
return sql_query, dataframe, figure, sql_queries, result_dataframes, figures, index_state, plot_title_list, ""
|
|
|
|
| 64 |
|
| 65 |
|
| 66 |
async def ask_ipcc(query: str, index_state: int = 0, user_id: str | None = None) -> tuple:
|
|
@@ -91,12 +96,16 @@ async def ask_ipcc(query: str, index_state: int = 0, user_id: str | None = None)
|
|
| 91 |
result_dataframes = []
|
| 92 |
figures = []
|
| 93 |
plot_title_list = []
|
| 94 |
-
|
| 95 |
|
| 96 |
for output_title, output in final_state['outputs'].items():
|
| 97 |
if output['status'] == 'OK':
|
| 98 |
if output['table'] is not None:
|
| 99 |
plot_title_list.append(output_title)
|
|
|
|
|
|
|
|
|
|
|
|
|
| 100 |
if output['sql_query'] is not None:
|
| 101 |
sql_queries.append(output['sql_query'])
|
| 102 |
|
|
@@ -106,13 +115,14 @@ async def ask_ipcc(query: str, index_state: int = 0, user_id: str | None = None)
|
|
| 106 |
figures.append(output['figure'])
|
| 107 |
|
| 108 |
if "error" in final_state and final_state["error"] != "":
|
| 109 |
-
# No Sql query, no dataframe, no figure, empty sql queries list, empty result dataframes list, empty figures list, index state = 0, empty table list, error message
|
| 110 |
-
return None, None, None, [], [], [], 0, [], final_state["error"]
|
| 111 |
|
| 112 |
sql_query = sql_queries[index_state]
|
| 113 |
dataframe = result_dataframes[index_state]
|
| 114 |
-
figure = figures[index_state](dataframe)
|
|
|
|
| 115 |
|
| 116 |
log_drias_interaction_to_huggingface(query, sql_query, user_id)
|
| 117 |
|
| 118 |
-
return sql_query, dataframe, figure, sql_queries, result_dataframes, figures, index_state, plot_title_list, ""
|
|
|
|
| 5 |
from climateqa.engine.talk_to_data.workflow.ipcc import ipcc_workflow
|
| 6 |
from climateqa.logging import log_drias_interaction_to_huggingface
|
| 7 |
from climateqa.logging import log_drias_interaction_to_huggingface
|
|
|
|
| 8 |
|
| 9 |
async def ask_drias(query: str, index_state: int = 0, user_id: str | None = None) -> tuple:
|
| 10 |
"""Main function to process a DRIAS query and return results.
|
|
|
|
| 34 |
result_dataframes = []
|
| 35 |
figures = []
|
| 36 |
plot_title_list = []
|
| 37 |
+
plot_informations = []
|
| 38 |
|
| 39 |
for output_title, output in final_state['outputs'].items():
|
| 40 |
if output['status'] == 'OK':
|
| 41 |
if output['table'] is not None:
|
| 42 |
plot_title_list.append(output_title)
|
| 43 |
+
|
| 44 |
+
if output['plot_information'] is not None:
|
| 45 |
+
plot_informations.append(output['plot_information'])
|
| 46 |
+
|
| 47 |
if output['sql_query'] is not None:
|
| 48 |
sql_queries.append(output['sql_query'])
|
| 49 |
|
|
|
|
| 53 |
figures.append(output['figure'])
|
| 54 |
|
| 55 |
if "error" in final_state and final_state["error"] != "":
|
| 56 |
+
# No Sql query, no dataframe, no figure, no plot information, empty sql queries list, empty result dataframes list, empty figures list, empty plot information list, index state = 0, empty table list, error message
|
| 57 |
+
return None, None, None, None, [], [], [], 0, [], final_state["error"]
|
| 58 |
|
| 59 |
sql_query = sql_queries[index_state]
|
| 60 |
dataframe = result_dataframes[index_state]
|
| 61 |
+
figure = figures[index_state](dataframe)
|
| 62 |
+
plot_information = plot_informations[index_state]
|
| 63 |
|
| 64 |
|
| 65 |
log_drias_interaction_to_huggingface(query, sql_query, user_id)
|
| 66 |
|
| 67 |
+
return sql_query, dataframe, figure, plot_information, sql_queries, result_dataframes, figures, plot_informations, index_state, plot_title_list, ""
|
| 68 |
+
|
| 69 |
|
| 70 |
|
| 71 |
async def ask_ipcc(query: str, index_state: int = 0, user_id: str | None = None) -> tuple:
|
|
|
|
| 96 |
result_dataframes = []
|
| 97 |
figures = []
|
| 98 |
plot_title_list = []
|
| 99 |
+
plot_informations = []
|
| 100 |
|
| 101 |
for output_title, output in final_state['outputs'].items():
|
| 102 |
if output['status'] == 'OK':
|
| 103 |
if output['table'] is not None:
|
| 104 |
plot_title_list.append(output_title)
|
| 105 |
+
|
| 106 |
+
if output['plot_information'] is not None:
|
| 107 |
+
plot_informations.append(output['plot_information'])
|
| 108 |
+
|
| 109 |
if output['sql_query'] is not None:
|
| 110 |
sql_queries.append(output['sql_query'])
|
| 111 |
|
|
|
|
| 115 |
figures.append(output['figure'])
|
| 116 |
|
| 117 |
if "error" in final_state and final_state["error"] != "":
|
| 118 |
+
# No Sql query, no dataframe, no figure, no plot information, empty sql queries list, empty result dataframes list, empty figures list, empty plot information list, index state = 0, empty table list, error message
|
| 119 |
+
return None, None, None, None, [], [], [], 0, [], final_state["error"]
|
| 120 |
|
| 121 |
sql_query = sql_queries[index_state]
|
| 122 |
dataframe = result_dataframes[index_state]
|
| 123 |
+
figure = figures[index_state](dataframe)
|
| 124 |
+
plot_information = plot_informations[index_state]
|
| 125 |
|
| 126 |
log_drias_interaction_to_huggingface(query, sql_query, user_id)
|
| 127 |
|
| 128 |
+
return sql_query, dataframe, figure, plot_information, sql_queries, result_dataframes, figures, plot_informations, index_state, plot_title_list, ""
|
climateqa/engine/talk_to_data/objects/plot.py
CHANGED
|
@@ -19,4 +19,5 @@ class Plot(TypedDict):
|
|
| 19 |
params: list[str]
|
| 20 |
plot_function: Callable[..., Callable[..., Figure]]
|
| 21 |
sql_query: Callable[..., str]
|
|
|
|
| 22 |
short_name: str
|
|
|
|
| 19 |
params: list[str]
|
| 20 |
plot_function: Callable[..., Callable[..., Figure]]
|
| 21 |
sql_query: Callable[..., str]
|
| 22 |
+
plot_information: Callable[..., str]
|
| 23 |
short_name: str
|
climateqa/engine/talk_to_data/objects/states.py
CHANGED
|
@@ -10,6 +10,7 @@ class TTDOutput(TypedDict):
|
|
| 10 |
sql_query: Optional[str]
|
| 11 |
dataframe: Optional[pd.DataFrame]
|
| 12 |
figure: Optional[Callable[..., Figure]]
|
|
|
|
| 13 |
class State(TypedDict):
|
| 14 |
user_input: str
|
| 15 |
plots: list[str]
|
|
|
|
| 10 |
sql_query: Optional[str]
|
| 11 |
dataframe: Optional[pd.DataFrame]
|
| 12 |
figure: Optional[Callable[..., Figure]]
|
| 13 |
+
plot_information: Optional[str]
|
| 14 |
class State(TypedDict):
|
| 15 |
user_input: str
|
| 16 |
plots: list[str]
|
climateqa/engine/talk_to_data/workflow/drias.py
CHANGED
|
@@ -37,7 +37,8 @@ async def process_output(
|
|
| 37 |
'table': table,
|
| 38 |
'sql_query': None,
|
| 39 |
'dataframe': None,
|
| 40 |
-
'figure': None
|
|
|
|
| 41 |
}
|
| 42 |
errors = {
|
| 43 |
'have_sql_query': False,
|
|
@@ -55,6 +56,8 @@ async def process_output(
|
|
| 55 |
results['status'] = 'ERROR'
|
| 56 |
return output_title, results, errors
|
| 57 |
|
|
|
|
|
|
|
| 58 |
results['sql_query'] = sql_query
|
| 59 |
errors['have_sql_query'] = True
|
| 60 |
|
|
@@ -142,6 +145,7 @@ async def drias_workflow(user_input: str) -> State:
|
|
| 142 |
outputs[output_title]['sql_query'] = task_results['sql_query']
|
| 143 |
outputs[output_title]['dataframe'] = task_results['dataframe']
|
| 144 |
outputs[output_title]['figure'] = task_results['figure']
|
|
|
|
| 145 |
outputs[output_title]['status'] = task_results['status']
|
| 146 |
errors['have_sql_query'] |= task_errors['have_sql_query']
|
| 147 |
errors['have_dataframe'] |= task_errors['have_dataframe']
|
|
|
|
| 37 |
'table': table,
|
| 38 |
'sql_query': None,
|
| 39 |
'dataframe': None,
|
| 40 |
+
'figure': None,
|
| 41 |
+
'plot_information': None
|
| 42 |
}
|
| 43 |
errors = {
|
| 44 |
'have_sql_query': False,
|
|
|
|
| 56 |
results['status'] = 'ERROR'
|
| 57 |
return output_title, results, errors
|
| 58 |
|
| 59 |
+
results['plot_information'] = plot['plot_information'](table, params)
|
| 60 |
+
|
| 61 |
results['sql_query'] = sql_query
|
| 62 |
errors['have_sql_query'] = True
|
| 63 |
|
|
|
|
| 145 |
outputs[output_title]['sql_query'] = task_results['sql_query']
|
| 146 |
outputs[output_title]['dataframe'] = task_results['dataframe']
|
| 147 |
outputs[output_title]['figure'] = task_results['figure']
|
| 148 |
+
outputs[output_title]['plot_information'] = task_results['plot_information']
|
| 149 |
outputs[output_title]['status'] = task_results['status']
|
| 150 |
errors['have_sql_query'] |= task_errors['have_sql_query']
|
| 151 |
errors['have_dataframe'] |= task_errors['have_dataframe']
|
climateqa/engine/talk_to_data/workflow/ipcc.py
CHANGED
|
@@ -37,7 +37,8 @@ async def process_output(
|
|
| 37 |
'table': table,
|
| 38 |
'sql_query': None,
|
| 39 |
'dataframe': None,
|
| 40 |
-
'figure': None
|
|
|
|
| 41 |
}
|
| 42 |
errors = {
|
| 43 |
'have_sql_query': False,
|
|
@@ -55,6 +56,8 @@ async def process_output(
|
|
| 55 |
results['status'] = 'ERROR'
|
| 56 |
return output_title, results, errors
|
| 57 |
|
|
|
|
|
|
|
| 58 |
results['sql_query'] = sql_query
|
| 59 |
errors['have_sql_query'] = True
|
| 60 |
|
|
@@ -140,6 +143,7 @@ async def ipcc_workflow(user_input: str) -> State:
|
|
| 140 |
outputs[output_title]['sql_query'] = task_results['sql_query']
|
| 141 |
outputs[output_title]['dataframe'] = task_results['dataframe']
|
| 142 |
outputs[output_title]['figure'] = task_results['figure']
|
|
|
|
| 143 |
outputs[output_title]['status'] = task_results['status']
|
| 144 |
errors['have_sql_query'] |= task_errors['have_sql_query']
|
| 145 |
errors['have_dataframe'] |= task_errors['have_dataframe']
|
|
|
|
| 37 |
'table': table,
|
| 38 |
'sql_query': None,
|
| 39 |
'dataframe': None,
|
| 40 |
+
'figure': None,
|
| 41 |
+
'plot_information': None,
|
| 42 |
}
|
| 43 |
errors = {
|
| 44 |
'have_sql_query': False,
|
|
|
|
| 56 |
results['status'] = 'ERROR'
|
| 57 |
return output_title, results, errors
|
| 58 |
|
| 59 |
+
results['plot_information'] = plot['plot_information'](table, params)
|
| 60 |
+
|
| 61 |
results['sql_query'] = sql_query
|
| 62 |
errors['have_sql_query'] = True
|
| 63 |
|
|
|
|
| 143 |
outputs[output_title]['sql_query'] = task_results['sql_query']
|
| 144 |
outputs[output_title]['dataframe'] = task_results['dataframe']
|
| 145 |
outputs[output_title]['figure'] = task_results['figure']
|
| 146 |
+
outputs[output_title]['plot_information'] = task_results['plot_information']
|
| 147 |
outputs[output_title]['status'] = task_results['status']
|
| 148 |
errors['have_sql_query'] |= task_errors['have_sql_query']
|
| 149 |
errors['have_dataframe'] |= task_errors['have_dataframe']
|
front/tabs/tab_drias.py
CHANGED
|
@@ -18,6 +18,7 @@ class DriasUIElements(TypedDict):
|
|
| 18 |
query_accordion: gr.Accordion
|
| 19 |
drias_sql_query: gr.Textbox
|
| 20 |
chart_accordion: gr.Accordion
|
|
|
|
| 21 |
model_selection: gr.Dropdown
|
| 22 |
drias_display: gr.Plot
|
| 23 |
table_accordion: gr.Accordion
|
|
@@ -64,13 +65,14 @@ def filter_by_model(dataframes, figures, index_state, model_selection):
|
|
| 64 |
return df, figure
|
| 65 |
|
| 66 |
|
| 67 |
-
def on_table_click(selected_label, table_names, sql_queries, dataframes, plots):
|
| 68 |
index = table_names.index(selected_label)
|
| 69 |
figure = plots[index](dataframes[index])
|
| 70 |
return (
|
| 71 |
sql_queries[index],
|
| 72 |
dataframes[index],
|
| 73 |
figure,
|
|
|
|
| 74 |
index,
|
| 75 |
)
|
| 76 |
|
|
@@ -132,6 +134,8 @@ def create_drias_ui() -> DriasUIElements:
|
|
| 132 |
|
| 133 |
|
| 134 |
with gr.Accordion(label="Chart", visible=False) as chart_accordion:
|
|
|
|
|
|
|
| 135 |
model_selection = gr.Dropdown(
|
| 136 |
label="Model", choices=DRIAS_MODELS, value="ALL", interactive=True
|
| 137 |
)
|
|
@@ -154,6 +158,7 @@ def create_drias_ui() -> DriasUIElements:
|
|
| 154 |
query_accordion=query_accordion,
|
| 155 |
drias_sql_query=drias_sql_query,
|
| 156 |
chart_accordion=chart_accordion,
|
|
|
|
| 157 |
model_selection=model_selection,
|
| 158 |
drias_display=drias_display,
|
| 159 |
table_accordion=table_accordion,
|
|
@@ -168,6 +173,7 @@ def setup_drias_events(ui_elements: DriasUIElements, share_client=None, user_id=
|
|
| 168 |
sql_queries_state = gr.State([])
|
| 169 |
dataframes_state = gr.State([])
|
| 170 |
plots_state = gr.State([])
|
|
|
|
| 171 |
index_state = gr.State(0)
|
| 172 |
table_names_list = gr.State([])
|
| 173 |
user_id = gr.State(user_id)
|
|
@@ -188,9 +194,11 @@ def setup_drias_events(ui_elements: DriasUIElements, share_client=None, user_id=
|
|
| 188 |
ui_elements["drias_sql_query"],
|
| 189 |
ui_elements["drias_table"],
|
| 190 |
ui_elements["drias_display"],
|
|
|
|
| 191 |
sql_queries_state,
|
| 192 |
dataframes_state,
|
| 193 |
plots_state,
|
|
|
|
| 194 |
index_state,
|
| 195 |
table_names_list,
|
| 196 |
ui_elements["result_text"],
|
|
@@ -226,6 +234,7 @@ def setup_drias_events(ui_elements: DriasUIElements, share_client=None, user_id=
|
|
| 226 |
sql_queries_state,
|
| 227 |
dataframes_state,
|
| 228 |
plots_state,
|
|
|
|
| 229 |
index_state,
|
| 230 |
table_names_list,
|
| 231 |
ui_elements["result_text"],
|
|
@@ -252,8 +261,8 @@ def setup_drias_events(ui_elements: DriasUIElements, share_client=None, user_id=
|
|
| 252 |
# Handle table selection
|
| 253 |
ui_elements["table_names_display"].change(
|
| 254 |
fn=on_table_click,
|
| 255 |
-
inputs=[ui_elements["table_names_display"], table_names_list, sql_queries_state, dataframes_state, plots_state],
|
| 256 |
-
outputs=[ui_elements["drias_sql_query"], ui_elements["drias_table"], ui_elements["drias_display"], index_state],
|
| 257 |
)
|
| 258 |
|
| 259 |
def create_drias_tab(share_client=None, user_id=None):
|
|
|
|
| 18 |
query_accordion: gr.Accordion
|
| 19 |
drias_sql_query: gr.Textbox
|
| 20 |
chart_accordion: gr.Accordion
|
| 21 |
+
plot_information: gr.Markdown
|
| 22 |
model_selection: gr.Dropdown
|
| 23 |
drias_display: gr.Plot
|
| 24 |
table_accordion: gr.Accordion
|
|
|
|
| 65 |
return df, figure
|
| 66 |
|
| 67 |
|
| 68 |
+
def on_table_click(selected_label, table_names, sql_queries, dataframes, plot_informations, plots):
|
| 69 |
index = table_names.index(selected_label)
|
| 70 |
figure = plots[index](dataframes[index])
|
| 71 |
return (
|
| 72 |
sql_queries[index],
|
| 73 |
dataframes[index],
|
| 74 |
figure,
|
| 75 |
+
plot_informations[index],
|
| 76 |
index,
|
| 77 |
)
|
| 78 |
|
|
|
|
| 134 |
|
| 135 |
|
| 136 |
with gr.Accordion(label="Chart", visible=False) as chart_accordion:
|
| 137 |
+
with gr.Accordion(label="Informations about the plot", open=False):
|
| 138 |
+
plot_information = gr.Markdown(value = "")
|
| 139 |
model_selection = gr.Dropdown(
|
| 140 |
label="Model", choices=DRIAS_MODELS, value="ALL", interactive=True
|
| 141 |
)
|
|
|
|
| 158 |
query_accordion=query_accordion,
|
| 159 |
drias_sql_query=drias_sql_query,
|
| 160 |
chart_accordion=chart_accordion,
|
| 161 |
+
plot_information=plot_information,
|
| 162 |
model_selection=model_selection,
|
| 163 |
drias_display=drias_display,
|
| 164 |
table_accordion=table_accordion,
|
|
|
|
| 173 |
sql_queries_state = gr.State([])
|
| 174 |
dataframes_state = gr.State([])
|
| 175 |
plots_state = gr.State([])
|
| 176 |
+
plot_informations_state = gr.State([])
|
| 177 |
index_state = gr.State(0)
|
| 178 |
table_names_list = gr.State([])
|
| 179 |
user_id = gr.State(user_id)
|
|
|
|
| 194 |
ui_elements["drias_sql_query"],
|
| 195 |
ui_elements["drias_table"],
|
| 196 |
ui_elements["drias_display"],
|
| 197 |
+
ui_elements["plot_information"],
|
| 198 |
sql_queries_state,
|
| 199 |
dataframes_state,
|
| 200 |
plots_state,
|
| 201 |
+
plot_informations_state,
|
| 202 |
index_state,
|
| 203 |
table_names_list,
|
| 204 |
ui_elements["result_text"],
|
|
|
|
| 234 |
sql_queries_state,
|
| 235 |
dataframes_state,
|
| 236 |
plots_state,
|
| 237 |
+
plot_informations_state,
|
| 238 |
index_state,
|
| 239 |
table_names_list,
|
| 240 |
ui_elements["result_text"],
|
|
|
|
| 261 |
# Handle table selection
|
| 262 |
ui_elements["table_names_display"].change(
|
| 263 |
fn=on_table_click,
|
| 264 |
+
inputs=[ui_elements["table_names_display"], table_names_list, sql_queries_state, dataframes_state, plot_informations_state, plots_state],
|
| 265 |
+
outputs=[ui_elements["drias_sql_query"], ui_elements["drias_table"], ui_elements["drias_display"], ui_elements["plot_information"], index_state],
|
| 266 |
)
|
| 267 |
|
| 268 |
def create_drias_tab(share_client=None, user_id=None):
|
front/tabs/tab_ipcc.py
CHANGED
|
@@ -19,6 +19,7 @@ class ipccUIElements(TypedDict):
|
|
| 19 |
query_accordion: gr.Accordion
|
| 20 |
ipcc_sql_query: gr.Textbox
|
| 21 |
chart_accordion: gr.Accordion
|
|
|
|
| 22 |
scenario_selection: gr.Dropdown
|
| 23 |
ipcc_display: gr.Plot
|
| 24 |
table_accordion: gr.Accordion
|
|
@@ -52,7 +53,7 @@ def show_results(sql_queries_state, dataframes_state, plots_state, table_names):
|
|
| 52 |
|
| 53 |
|
| 54 |
def show_filter_by_scenario(table_names, index_state, dataframes):
|
| 55 |
-
if table_names[index_state].startswith("Choropleth Map"):
|
| 56 |
df = dataframes[index_state]
|
| 57 |
return gr.update(visible=True, choices=sorted(df["scenario"].unique()), value=df["scenario"].unique()[0])
|
| 58 |
else:
|
|
@@ -78,13 +79,14 @@ def display_table_names(table_names, index_state):
|
|
| 78 |
for name in table_names
|
| 79 |
]
|
| 80 |
|
| 81 |
-
def on_table_click(selected_label, table_names, sql_queries, dataframes, plots):
|
| 82 |
index = table_names.index(selected_label)
|
| 83 |
figure = plots[index](dataframes[index])
|
| 84 |
return (
|
| 85 |
sql_queries[index],
|
| 86 |
dataframes[index],
|
| 87 |
figure,
|
|
|
|
| 88 |
index,
|
| 89 |
)
|
| 90 |
|
|
@@ -144,6 +146,9 @@ def create_ipcc_ui() -> ipccUIElements:
|
|
| 144 |
)
|
| 145 |
|
| 146 |
with gr.Accordion(label="Chart", visible=False) as chart_accordion:
|
|
|
|
|
|
|
|
|
|
| 147 |
scenario_selection = gr.Dropdown(
|
| 148 |
label="Scenario", choices=IPCC_MODELS, value="ALL", interactive=True, visible=False
|
| 149 |
)
|
|
@@ -167,6 +172,7 @@ def create_ipcc_ui() -> ipccUIElements:
|
|
| 167 |
query_accordion=query_accordion,
|
| 168 |
ipcc_sql_query=ipcc_sql_query,
|
| 169 |
chart_accordion=chart_accordion,
|
|
|
|
| 170 |
scenario_selection=scenario_selection,
|
| 171 |
ipcc_display=ipcc_display,
|
| 172 |
table_accordion=table_accordion,
|
|
@@ -181,6 +187,7 @@ def setup_ipcc_events(ui_elements: ipccUIElements, share_client=None, user_id=No
|
|
| 181 |
sql_queries_state = gr.State([])
|
| 182 |
dataframes_state = gr.State([])
|
| 183 |
plots_state = gr.State([])
|
|
|
|
| 184 |
index_state = gr.State(0)
|
| 185 |
table_names_list = gr.State([])
|
| 186 |
user_id = gr.State(user_id)
|
|
@@ -201,9 +208,11 @@ def setup_ipcc_events(ui_elements: ipccUIElements, share_client=None, user_id=No
|
|
| 201 |
ui_elements["ipcc_sql_query"],
|
| 202 |
ui_elements["ipcc_table"],
|
| 203 |
ui_elements["ipcc_display"],
|
|
|
|
| 204 |
sql_queries_state,
|
| 205 |
dataframes_state,
|
| 206 |
plots_state,
|
|
|
|
| 207 |
index_state,
|
| 208 |
table_names_list,
|
| 209 |
ui_elements["result_text"],
|
|
@@ -240,9 +249,11 @@ def setup_ipcc_events(ui_elements: ipccUIElements, share_client=None, user_id=No
|
|
| 240 |
ui_elements["ipcc_sql_query"],
|
| 241 |
ui_elements["ipcc_table"],
|
| 242 |
ui_elements["ipcc_display"],
|
|
|
|
| 243 |
sql_queries_state,
|
| 244 |
dataframes_state,
|
| 245 |
plots_state,
|
|
|
|
| 246 |
index_state,
|
| 247 |
table_names_list,
|
| 248 |
ui_elements["result_text"],
|
|
@@ -273,8 +284,8 @@ def setup_ipcc_events(ui_elements: ipccUIElements, share_client=None, user_id=No
|
|
| 273 |
# Handle table selection
|
| 274 |
ui_elements["table_names_display"].change(
|
| 275 |
fn=on_table_click,
|
| 276 |
-
inputs=[ui_elements["table_names_display"], table_names_list, sql_queries_state, dataframes_state, plots_state],
|
| 277 |
-
outputs=[ui_elements["ipcc_sql_query"], ui_elements["ipcc_table"], ui_elements["ipcc_display"], index_state],
|
| 278 |
).then(
|
| 279 |
show_filter_by_scenario,
|
| 280 |
inputs=[table_names_list, index_state, dataframes_state],
|
|
|
|
| 19 |
query_accordion: gr.Accordion
|
| 20 |
ipcc_sql_query: gr.Textbox
|
| 21 |
chart_accordion: gr.Accordion
|
| 22 |
+
plot_information: gr.Markdown
|
| 23 |
scenario_selection: gr.Dropdown
|
| 24 |
ipcc_display: gr.Plot
|
| 25 |
table_accordion: gr.Accordion
|
|
|
|
| 53 |
|
| 54 |
|
| 55 |
def show_filter_by_scenario(table_names, index_state, dataframes):
|
| 56 |
+
if len(table_names) > 0 and table_names[index_state].startswith("Choropleth Map"):
|
| 57 |
df = dataframes[index_state]
|
| 58 |
return gr.update(visible=True, choices=sorted(df["scenario"].unique()), value=df["scenario"].unique()[0])
|
| 59 |
else:
|
|
|
|
| 79 |
for name in table_names
|
| 80 |
]
|
| 81 |
|
| 82 |
+
def on_table_click(selected_label, table_names, sql_queries, dataframes, plot_informations, plots):
|
| 83 |
index = table_names.index(selected_label)
|
| 84 |
figure = plots[index](dataframes[index])
|
| 85 |
return (
|
| 86 |
sql_queries[index],
|
| 87 |
dataframes[index],
|
| 88 |
figure,
|
| 89 |
+
plot_informations[index],
|
| 90 |
index,
|
| 91 |
)
|
| 92 |
|
|
|
|
| 146 |
)
|
| 147 |
|
| 148 |
with gr.Accordion(label="Chart", visible=False) as chart_accordion:
|
| 149 |
+
with gr.Accordion(label="Informations about the plot", open=False):
|
| 150 |
+
plot_information = gr.Markdown(value = "")
|
| 151 |
+
|
| 152 |
scenario_selection = gr.Dropdown(
|
| 153 |
label="Scenario", choices=IPCC_MODELS, value="ALL", interactive=True, visible=False
|
| 154 |
)
|
|
|
|
| 172 |
query_accordion=query_accordion,
|
| 173 |
ipcc_sql_query=ipcc_sql_query,
|
| 174 |
chart_accordion=chart_accordion,
|
| 175 |
+
plot_information=plot_information,
|
| 176 |
scenario_selection=scenario_selection,
|
| 177 |
ipcc_display=ipcc_display,
|
| 178 |
table_accordion=table_accordion,
|
|
|
|
| 187 |
sql_queries_state = gr.State([])
|
| 188 |
dataframes_state = gr.State([])
|
| 189 |
plots_state = gr.State([])
|
| 190 |
+
plot_informations_state = gr.State([])
|
| 191 |
index_state = gr.State(0)
|
| 192 |
table_names_list = gr.State([])
|
| 193 |
user_id = gr.State(user_id)
|
|
|
|
| 208 |
ui_elements["ipcc_sql_query"],
|
| 209 |
ui_elements["ipcc_table"],
|
| 210 |
ui_elements["ipcc_display"],
|
| 211 |
+
ui_elements["plot_information"],
|
| 212 |
sql_queries_state,
|
| 213 |
dataframes_state,
|
| 214 |
plots_state,
|
| 215 |
+
plot_informations_state,
|
| 216 |
index_state,
|
| 217 |
table_names_list,
|
| 218 |
ui_elements["result_text"],
|
|
|
|
| 249 |
ui_elements["ipcc_sql_query"],
|
| 250 |
ui_elements["ipcc_table"],
|
| 251 |
ui_elements["ipcc_display"],
|
| 252 |
+
ui_elements["plot_information"],
|
| 253 |
sql_queries_state,
|
| 254 |
dataframes_state,
|
| 255 |
plots_state,
|
| 256 |
+
plot_informations_state,
|
| 257 |
index_state,
|
| 258 |
table_names_list,
|
| 259 |
ui_elements["result_text"],
|
|
|
|
| 284 |
# Handle table selection
|
| 285 |
ui_elements["table_names_display"].change(
|
| 286 |
fn=on_table_click,
|
| 287 |
+
inputs=[ui_elements["table_names_display"], table_names_list, sql_queries_state, dataframes_state, plot_informations_state, plots_state],
|
| 288 |
+
outputs=[ui_elements["ipcc_sql_query"], ui_elements["ipcc_table"], ui_elements["ipcc_display"], ui_elements["plot_information"], index_state],
|
| 289 |
).then(
|
| 290 |
show_filter_by_scenario,
|
| 291 |
inputs=[table_names_list, index_state, dataframes_state],
|