Add examples
Browse files- front/tabs/tab_drias.py +58 -4
    	
        front/tabs/tab_drias.py
    CHANGED
    
    | @@ -95,7 +95,22 @@ def create_drias_tab(): | |
| 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(
         | 
| 101 | 
             
                            label="Direct Question",
         | 
| @@ -104,6 +119,7 @@ def create_drias_tab(): | |
| 104 | 
             
                            interactive=True,
         | 
| 105 | 
             
                        )
         | 
| 106 |  | 
|  | |
| 107 | 
             
                    result_text = gr.Textbox(
         | 
| 108 | 
             
                        label="", elem_id="no-result-label", interactive=False, visible=True
         | 
| 109 | 
             
                    )
         | 
| @@ -117,8 +133,6 @@ def create_drias_tab(): | |
| 117 | 
             
                            label="", elem_id="sql-query", interactive=False
         | 
| 118 | 
             
                        )
         | 
| 119 |  | 
| 120 | 
            -
             | 
| 121 | 
            -
             | 
| 122 | 
             
                    with gr.Accordion(label="Chart", visible=False) as chart_accordion:
         | 
| 123 | 
             
                        model_selection = gr.Dropdown(
         | 
| 124 | 
             
                            label="Model", choices=DRIAS_MODELS, value="ALL", interactive=True
         | 
| @@ -138,6 +152,44 @@ def create_drias_tab(): | |
| 138 | 
             
                        prev_button = gr.Button("Previous", visible=False)
         | 
| 139 | 
             
                        next_button = gr.Button("Next", visible=False)
         | 
| 140 |  | 
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
| 141 | 
             
                    drias_direct_question.submit(
         | 
| 142 | 
             
                        ask_drias_query,
         | 
| 143 | 
             
                        inputs=[drias_direct_question, index_state],
         | 
| @@ -210,4 +262,6 @@ def create_drias_tab(): | |
| 210 | 
             
                        update_pagination,
         | 
| 211 | 
             
                        inputs=[index_state, sql_queries_state],
         | 
| 212 | 
             
                        outputs=[pagination_display],
         | 
| 213 | 
            -
                    )
         | 
|  | |
|  | 
|  | |
| 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 | 
            +
                            # Add examples for common questions
         | 
| 100 | 
            +
                    examples_hidden = gr.Textbox(visible=False, elem_id="drias-examples-hidden")
         | 
| 101 | 
            +
                    examples = gr.Examples(
         | 
| 102 | 
            +
                        examples=[
         | 
| 103 | 
            +
                            ["What will the temperature be like in Paris?"],
         | 
| 104 | 
            +
                            ["What will be the total rainfall in France in 2030?"],
         | 
| 105 | 
            +
                            ["How frequent will extreme events be in Lyon?"],
         | 
| 106 | 
            +
                            ["Comment va évoluer la température en France entre 2030 et 2050 ?"]
         | 
| 107 | 
            +
                        ],
         | 
| 108 | 
            +
                        label="Example Questions",
         | 
| 109 | 
            +
                        inputs=[examples_hidden],
         | 
| 110 | 
            +
                        outputs=[examples_hidden],
         | 
| 111 | 
            +
                    )
         | 
| 112 | 
            +
                    
         | 
| 113 | 
            +
                
         | 
| 114 | 
             
                    with gr.Row():
         | 
| 115 | 
             
                        drias_direct_question = gr.Textbox(
         | 
| 116 | 
             
                            label="Direct Question",
         | 
|  | |
| 119 | 
             
                            interactive=True,
         | 
| 120 | 
             
                        )
         | 
| 121 |  | 
| 122 | 
            +
             | 
| 123 | 
             
                    result_text = gr.Textbox(
         | 
| 124 | 
             
                        label="", elem_id="no-result-label", interactive=False, visible=True
         | 
| 125 | 
             
                    )
         | 
|  | |
| 133 | 
             
                            label="", elem_id="sql-query", interactive=False
         | 
| 134 | 
             
                        )
         | 
| 135 |  | 
|  | |
|  | |
| 136 | 
             
                    with gr.Accordion(label="Chart", visible=False) as chart_accordion:
         | 
| 137 | 
             
                        model_selection = gr.Dropdown(
         | 
| 138 | 
             
                            label="Model", choices=DRIAS_MODELS, value="ALL", interactive=True
         | 
|  | |
| 152 | 
             
                        prev_button = gr.Button("Previous", visible=False)
         | 
| 153 | 
             
                        next_button = gr.Button("Next", visible=False)
         | 
| 154 |  | 
| 155 | 
            +
                    # Handle example selection
         | 
| 156 | 
            +
                    examples_hidden.change(
         | 
| 157 | 
            +
                        ask_drias_query,
         | 
| 158 | 
            +
                        inputs=[examples_hidden, index_state],
         | 
| 159 | 
            +
                        outputs=[
         | 
| 160 | 
            +
                            drias_sql_query,
         | 
| 161 | 
            +
                            drias_table,
         | 
| 162 | 
            +
                            drias_display,
         | 
| 163 | 
            +
                            sql_queries_state,
         | 
| 164 | 
            +
                            dataframes_state,
         | 
| 165 | 
            +
                            plots_state,
         | 
| 166 | 
            +
                            index_state,
         | 
| 167 | 
            +
                            table_names_list,
         | 
| 168 | 
            +
                            result_text,
         | 
| 169 | 
            +
                        ],
         | 
| 170 | 
            +
                    ).then(
         | 
| 171 | 
            +
                        show_results,
         | 
| 172 | 
            +
                        inputs=[sql_queries_state, dataframes_state, plots_state],
         | 
| 173 | 
            +
                        outputs=[
         | 
| 174 | 
            +
                            result_text,
         | 
| 175 | 
            +
                            query_accordion,
         | 
| 176 | 
            +
                            table_accordion,
         | 
| 177 | 
            +
                            chart_accordion,
         | 
| 178 | 
            +
                            prev_button,
         | 
| 179 | 
            +
                            next_button,
         | 
| 180 | 
            +
                            pagination_display,
         | 
| 181 | 
            +
                            table_names_display,
         | 
| 182 | 
            +
                        ],
         | 
| 183 | 
            +
                    ).then(
         | 
| 184 | 
            +
                        update_pagination,
         | 
| 185 | 
            +
                        inputs=[index_state, sql_queries_state],
         | 
| 186 | 
            +
                        outputs=[pagination_display],
         | 
| 187 | 
            +
                    ).then(
         | 
| 188 | 
            +
                        display_table_names,
         | 
| 189 | 
            +
                        inputs=[table_names_list],
         | 
| 190 | 
            +
                        outputs=[table_names_display],
         | 
| 191 | 
            +
                    )
         | 
| 192 | 
            +
             | 
| 193 | 
             
                    drias_direct_question.submit(
         | 
| 194 | 
             
                        ask_drias_query,
         | 
| 195 | 
             
                        inputs=[drias_direct_question, index_state],
         | 
|  | |
| 262 | 
             
                        update_pagination,
         | 
| 263 | 
             
                        inputs=[index_state, sql_queries_state],
         | 
| 264 | 
             
                        outputs=[pagination_display],
         | 
| 265 | 
            +
                    )
         | 
| 266 | 
            +
                    
         | 
| 267 | 
            +
                   
         | 

