Move hardcoded configuration in a config file
Browse files
    	
        climateqa/engine/talk_to_data/config.py
    CHANGED
    
    | @@ -30,4 +30,53 @@ INDICATOR_COLUMNS_PER_TABLE = { | |
| 30 | 
             
                "number_of_days_with_tx_above_30": "number_of_days_with_tx_above_30",
         | 
| 31 | 
             
                "number_of_days_with_tx_above_35": "number_of_days_with_tx_above_35",
         | 
| 32 | 
             
                "number_of_days_with_a_dry_ground": "number_of_days_with_dry_ground"
         | 
| 33 | 
            -
            }
         | 
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | 
|  | |
| 30 | 
             
                "number_of_days_with_tx_above_30": "number_of_days_with_tx_above_30",
         | 
| 31 | 
             
                "number_of_days_with_tx_above_35": "number_of_days_with_tx_above_35",
         | 
| 32 | 
             
                "number_of_days_with_a_dry_ground": "number_of_days_with_dry_ground"
         | 
| 33 | 
            +
            }
         | 
| 34 | 
            +
             | 
| 35 | 
            +
            DRIAS_MODELS = [
         | 
| 36 | 
            +
                'ALL',
         | 
| 37 | 
            +
                'RegCM4-6_MPI-ESM-LR',
         | 
| 38 | 
            +
                'RACMO22E_EC-EARTH',
         | 
| 39 | 
            +
                'RegCM4-6_HadGEM2-ES',
         | 
| 40 | 
            +
                'HadREM3-GA7_EC-EARTH',
         | 
| 41 | 
            +
                'HadREM3-GA7_CNRM-CM5',
         | 
| 42 | 
            +
                'REMO2015_NorESM1-M',
         | 
| 43 | 
            +
                'SMHI-RCA4_EC-EARTH',
         | 
| 44 | 
            +
                'WRF381P_NorESM1-M',
         | 
| 45 | 
            +
                'ALADIN63_CNRM-CM5',
         | 
| 46 | 
            +
                'CCLM4-8-17_MPI-ESM-LR',
         | 
| 47 | 
            +
                'HIRHAM5_IPSL-CM5A-MR',
         | 
| 48 | 
            +
                'HadREM3-GA7_HadGEM2-ES',
         | 
| 49 | 
            +
                'SMHI-RCA4_IPSL-CM5A-MR',
         | 
| 50 | 
            +
                'HIRHAM5_NorESM1-M',
         | 
| 51 | 
            +
                'REMO2009_MPI-ESM-LR',
         | 
| 52 | 
            +
                'CCLM4-8-17_HadGEM2-ES'
         | 
| 53 | 
            +
            ]
         | 
| 54 | 
            +
             | 
| 55 | 
            +
            DRIAS_UI_TEXT = """
         | 
| 56 | 
            +
            Hi, I'm **Talk to Drias**, designed to answer your questions using [**DRIAS - TRACC 2023**](https://www.drias-climat.fr/accompagnement/sections/401) data.  
         | 
| 57 | 
            +
            I'll answer by displaying a list of SQL queries, graphs and data most relevant to your question.
         | 
| 58 | 
            +
             | 
| 59 | 
            +
            ❓ **How to use?**  
         | 
| 60 | 
            +
            You can ask me anything about these climate indicators: **temperature**, **precipitation** or **drought**.  
         | 
| 61 | 
            +
            You can specify **location** and/or **year**.  
         | 
| 62 | 
            +
            You can choose from a list of climate models. By default, we take the **average of each model**.
         | 
| 63 | 
            +
             | 
| 64 | 
            +
            For example, you can ask:  
         | 
| 65 | 
            +
            - What will the temperature be like in Paris?  
         | 
| 66 | 
            +
            - What will be the total rainfall in France in 2030?  
         | 
| 67 | 
            +
            - How frequent will extreme events be in Lyon?  
         | 
| 68 | 
            +
             | 
| 69 | 
            +
            **Example of indicators in the data**:  
         | 
| 70 | 
            +
            - Mean temperature (annual, winter, summer)  
         | 
| 71 | 
            +
            - Total precipitation (annual, winter, summer)  
         | 
| 72 | 
            +
            - Number of days with remarkable precipitations, with dry ground, with temperature above 30°C  
         | 
| 73 | 
            +
             | 
| 74 | 
            +
            ⚠️ **Limitations**:  
         | 
| 75 | 
            +
            - You can't ask anything that isn't related to **DRIAS - TRACC 2023** data.  
         | 
| 76 | 
            +
            - You can only ask about **locations in France**.  
         | 
| 77 | 
            +
            - If you specify a year, there may be **no data for that year for some models**.  
         | 
| 78 | 
            +
            - You **cannot compare two models**.  
         | 
| 79 | 
            +
             | 
| 80 | 
            +
            🛈 **Information**  
         | 
| 81 | 
            +
            Please note that we **log your questions for meta-analysis purposes**, so avoid sharing any sensitive or personal information.
         | 
| 82 | 
            +
            """
         | 
    	
        climateqa/engine/talk_to_data/main.py
    CHANGED
    
    | @@ -88,25 +88,6 @@ def ask_drias(query: str, index_state: int = 0) -> tuple: | |
| 88 |  | 
| 89 | 
             
                return sql_query, dataframe, figure, sql_queries, result_dataframes, figures, index_state, table_list, ""
         | 
| 90 |  | 
| 91 | 
            -
            DRIAS_MODELS = [
         | 
| 92 | 
            -
                'ALL',
         | 
| 93 | 
            -
                'RegCM4-6_MPI-ESM-LR',
         | 
| 94 | 
            -
                'RACMO22E_EC-EARTH',
         | 
| 95 | 
            -
                'RegCM4-6_HadGEM2-ES',
         | 
| 96 | 
            -
                'HadREM3-GA7_EC-EARTH',
         | 
| 97 | 
            -
                'HadREM3-GA7_CNRM-CM5',
         | 
| 98 | 
            -
                'REMO2015_NorESM1-M',
         | 
| 99 | 
            -
                'SMHI-RCA4_EC-EARTH',
         | 
| 100 | 
            -
                'WRF381P_NorESM1-M',
         | 
| 101 | 
            -
                'ALADIN63_CNRM-CM5',
         | 
| 102 | 
            -
                'CCLM4-8-17_MPI-ESM-LR',
         | 
| 103 | 
            -
                'HIRHAM5_IPSL-CM5A-MR',
         | 
| 104 | 
            -
                'HadREM3-GA7_HadGEM2-ES',
         | 
| 105 | 
            -
                'SMHI-RCA4_IPSL-CM5A-MR',
         | 
| 106 | 
            -
                'HIRHAM5_NorESM1-M',
         | 
| 107 | 
            -
                'REMO2009_MPI-ESM-LR',
         | 
| 108 | 
            -
                'CCLM4-8-17_HadGEM2-ES'
         | 
| 109 | 
            -
            ]
         | 
| 110 | 
             
            # def ask_vanna(vn,db_vanna_path, query):
         | 
| 111 |  | 
| 112 | 
             
            #     try :
         | 
|  | |
| 88 |  | 
| 89 | 
             
                return sql_query, dataframe, figure, sql_queries, result_dataframes, figures, index_state, table_list, ""
         | 
| 90 |  | 
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
| 91 | 
             
            # def ask_vanna(vn,db_vanna_path, query):
         | 
| 92 |  | 
| 93 | 
             
            #     try :
         | 
    	
        climateqa/engine/talk_to_data/workflow.py
    CHANGED
    
    | @@ -19,8 +19,6 @@ from climateqa.engine.talk_to_data.utils import ( | |
| 19 |  | 
| 20 | 
             
            ROOT_PATH = os.path.dirname(os.path.dirname(os.getcwd()))
         | 
| 21 |  | 
| 22 | 
            -
            DRIAS_DB_PATH = ROOT_PATH + "/data/drias/drias.db"
         | 
| 23 | 
            -
             | 
| 24 | 
             
            class TableState(TypedDict):
         | 
| 25 | 
             
                """Represents the state of a table in the DRIAS workflow.
         | 
| 26 |  | 
|  | |
| 19 |  | 
| 20 | 
             
            ROOT_PATH = os.path.dirname(os.path.dirname(os.getcwd()))
         | 
| 21 |  | 
|  | |
|  | |
| 22 | 
             
            class TableState(TypedDict):
         | 
| 23 | 
             
                """Represents the state of a table in the DRIAS workflow.
         | 
| 24 |  | 
    	
        front/tabs/tab_drias.py
    CHANGED
    
    | @@ -1,6 +1,7 @@ | |
| 1 | 
             
            import gradio as gr
         | 
| 2 |  | 
| 3 | 
            -
            from climateqa.engine.talk_to_data.main import ask_drias | 
|  | |
| 4 |  | 
| 5 |  | 
| 6 | 
             
            def ask_drias_query(query: str, index_state: int):
         | 
| @@ -84,36 +85,6 @@ def on_table_click(evt: gr.SelectData, table_names, sql_queries, dataframes, plo | |
| 84 | 
             
                )
         | 
| 85 |  | 
| 86 |  | 
| 87 | 
            -
            DETAILS_TEXT = """
         | 
| 88 | 
            -
            Hi, I'm **Talk to Drias**, designed to answer your questions using [**DRIAS - TRACC 2023**](https://www.drias-climat.fr/accompagnement/sections/401) data.  
         | 
| 89 | 
            -
            I'll answer by displaying a list of SQL queries, graphs and data most relevant to your question.
         | 
| 90 | 
            -
             | 
| 91 | 
            -
            ❓ **How to use?**  
         | 
| 92 | 
            -
            You can ask me anything about these climate indicators: **temperature**, **precipitation** or **drought**.  
         | 
| 93 | 
            -
            You can specify **location** and/or **year**.  
         | 
| 94 | 
            -
            You can choose from a list of climate models. By default, we take the **average of each model**.
         | 
| 95 | 
            -
             | 
| 96 | 
            -
            For example, you can ask:  
         | 
| 97 | 
            -
            - What will the temperature be like in Paris?  
         | 
| 98 | 
            -
            - What will be the total rainfall in France in 2030?  
         | 
| 99 | 
            -
            - How frequent will extreme events be in Lyon?  
         | 
| 100 | 
            -
             | 
| 101 | 
            -
            **Example of indicators in the data**:  
         | 
| 102 | 
            -
            - Mean temperature (annual, winter, summer)  
         | 
| 103 | 
            -
            - Total precipitation (annual, winter, summer)  
         | 
| 104 | 
            -
            - Number of days with remarkable precipitations, with dry ground, with temperature above 30°C  
         | 
| 105 | 
            -
             | 
| 106 | 
            -
            ⚠️ **Limitations**:  
         | 
| 107 | 
            -
            - You can't ask anything that isn't related to **DRIAS - TRACC 2023** data.  
         | 
| 108 | 
            -
            - You can only ask about **locations in France**.  
         | 
| 109 | 
            -
            - If you specify a year, there may be **no data for that year for some models**.  
         | 
| 110 | 
            -
            - You **cannot compare two models**.  
         | 
| 111 | 
            -
             | 
| 112 | 
            -
            🛈 **Information**  
         | 
| 113 | 
            -
            Please note that we **log your questions for meta-analysis purposes**, so avoid sharing any sensitive or personal information.
         | 
| 114 | 
            -
            """
         | 
| 115 | 
            -
             | 
| 116 | 
            -
             | 
| 117 | 
             
            def create_drias_tab():
         | 
| 118 | 
             
                sql_queries_state = gr.State([])
         | 
| 119 | 
             
                dataframes_state = gr.State([])
         | 
| @@ -123,7 +94,7 @@ def create_drias_tab(): | |
| 123 |  | 
| 124 | 
             
                with gr.Tab("Beta - Talk to DRIAS", elem_id="tab-vanna", id=6):
         | 
| 125 | 
             
                    with gr.Accordion(label="Details"):
         | 
| 126 | 
            -
                        gr.Markdown( | 
| 127 |  | 
| 128 | 
             
                    with gr.Row():
         | 
| 129 | 
             
                        drias_direct_question = gr.Textbox(
         | 
|  | |
| 1 | 
             
            import gradio as gr
         | 
| 2 |  | 
| 3 | 
            +
            from climateqa.engine.talk_to_data.main import ask_drias
         | 
| 4 | 
            +
            from climateqa.engine.talk_to_data.config import DRIAS_MODELS, DRIAS_UI_TEXT
         | 
| 5 |  | 
| 6 |  | 
| 7 | 
             
            def ask_drias_query(query: str, index_state: int):
         | 
|  | |
| 85 | 
             
                )
         | 
| 86 |  | 
| 87 |  | 
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
| 88 | 
             
            def create_drias_tab():
         | 
| 89 | 
             
                sql_queries_state = gr.State([])
         | 
| 90 | 
             
                dataframes_state = gr.State([])
         | 
|  | |
| 94 |  | 
| 95 | 
             
                with gr.Tab("Beta - Talk to DRIAS", elem_id="tab-vanna", id=6):
         | 
| 96 | 
             
                    with gr.Accordion(label="Details"):
         | 
| 97 | 
            +
                        gr.Markdown(DRIAS_UI_TEXT)
         | 
| 98 |  | 
| 99 | 
             
                    with gr.Row():
         | 
| 100 | 
             
                        drias_direct_question = gr.Textbox(
         | 

