config in a modal object
Browse files
app.py
CHANGED
|
@@ -117,6 +117,9 @@ reranker = get_reranker("nano")
|
|
| 117 |
|
| 118 |
agent = make_graph_agent(llm=llm, vectorstore_ipcc=vectorstore, vectorstore_graphs=vectorstore_graphs, reranker=reranker)
|
| 119 |
|
|
|
|
|
|
|
|
|
|
| 120 |
|
| 121 |
async def chat(query, history, audience, sources, reports, relevant_content_sources, search_only):
|
| 122 |
"""taking a query and a message history, use a pipeline (reformulation, retriever, answering) to yield a tuple of:
|
|
@@ -293,6 +296,7 @@ with gr.Blocks(title="Climate Q&A", css_paths=os.getcwd()+ "/style.css", theme=t
|
|
| 293 |
chat_completed_state = gr.State(0)
|
| 294 |
current_graphs = gr.State([])
|
| 295 |
saved_graphs = gr.State({})
|
|
|
|
| 296 |
|
| 297 |
|
| 298 |
with gr.Tab("ClimateQ&A"):
|
|
@@ -317,7 +321,11 @@ with gr.Blocks(title="Climate Q&A", css_paths=os.getcwd()+ "/style.css", theme=t
|
|
| 317 |
|
| 318 |
with gr.Row(elem_id = "input-message"):
|
| 319 |
textbox=gr.Textbox(placeholder="Ask me anything here!",show_label=False,scale=7,lines = 1,interactive = True,elem_id="input-textbox")
|
| 320 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 321 |
|
| 322 |
with gr.Column(scale=2, variant="panel",elem_id = "right-panel"):
|
| 323 |
|
|
@@ -349,54 +357,54 @@ with gr.Blocks(title="Climate Q&A", css_paths=os.getcwd()+ "/style.css", theme=t
|
|
| 349 |
|
| 350 |
samples.append(group_examples)
|
| 351 |
|
| 352 |
-
with gr.Tab("Configuration", id = 10, ) as tab_config:
|
| 353 |
-
|
| 354 |
-
|
| 355 |
|
|
|
|
| 356 |
|
| 357 |
-
with gr.Row():
|
| 358 |
|
| 359 |
-
|
| 360 |
-
|
| 361 |
-
|
| 362 |
-
|
| 363 |
-
|
| 364 |
-
|
| 365 |
-
|
| 366 |
-
|
| 367 |
-
|
| 368 |
-
|
| 369 |
-
|
| 370 |
-
|
| 371 |
-
|
| 372 |
-
dropdown_reports = gr.Dropdown(
|
| 373 |
-
|
| 374 |
-
|
| 375 |
-
|
| 376 |
-
|
| 377 |
-
|
| 378 |
-
)
|
| 379 |
-
|
| 380 |
-
search_only = gr.Checkbox(label="Search only without chating", value=False, interactive=True, elem_id="checkbox-chat")
|
| 381 |
-
|
| 382 |
-
|
| 383 |
-
dropdown_audience = gr.Dropdown(
|
| 384 |
-
|
| 385 |
-
|
| 386 |
-
|
| 387 |
-
|
| 388 |
-
)
|
| 389 |
|
| 390 |
|
| 391 |
-
after = gr.Slider(minimum=1950,maximum=2023,step=1,value=1960,label="Publication date",show_label=True,interactive=True,elem_id="date-papers", visible=False)
|
| 392 |
-
|
| 393 |
|
| 394 |
-
output_query = gr.Textbox(label="Query used for retrieval",show_label = True,elem_id = "reformulated-query",lines = 2,interactive = False, visible= False)
|
| 395 |
-
output_language = gr.Textbox(label="Language",show_label = True,elem_id = "language",lines = 1,interactive = False, visible= False)
|
| 396 |
|
| 397 |
|
| 398 |
-
dropdown_external_sources.change(lambda x: gr.update(visible = True ) if "OpenAlex" in x else gr.update(visible=False) , inputs=[dropdown_external_sources], outputs=[after])
|
| 399 |
-
# dropdown_external_sources.change(lambda x: gr.update(visible = True ) if "OpenAlex" in x else gr.update(visible=False) , inputs=[dropdown_external_sources], outputs=[after], visible=True)
|
| 400 |
|
| 401 |
|
| 402 |
with gr.Tab("Sources",elem_id = "tab-sources",id = 1) as tab_sources:
|
|
@@ -411,11 +419,11 @@ with gr.Blocks(title="Climate Q&A", css_paths=os.getcwd()+ "/style.css", theme=t
|
|
| 411 |
with gr.Tab("Figures",elem_id = "tab-figures",id = 3) as tab_figures:
|
| 412 |
sources_raw = gr.State()
|
| 413 |
|
| 414 |
-
with Modal(visible=False, elem_id="modal_figure_galery") as
|
| 415 |
gallery_component = gr.Gallery(object_fit='scale-down',elem_id="gallery-component", height="80vh")
|
| 416 |
|
| 417 |
show_full_size_figures = gr.Button("Show figures in full size",elem_id="show-figures",interactive=True)
|
| 418 |
-
show_full_size_figures.click(lambda : Modal(visible=True),None,
|
| 419 |
|
| 420 |
figures_cards = gr.HTML(show_label=False, elem_id="sources-figures")
|
| 421 |
|
|
@@ -435,9 +443,9 @@ with gr.Blocks(title="Climate Q&A", css_paths=os.getcwd()+ "/style.css", theme=t
|
|
| 435 |
|
| 436 |
btn_citations_network = gr.Button("Explore papers citations network")
|
| 437 |
# Fenêtre simulée pour le Citations Network
|
| 438 |
-
with Modal(visible=False) as
|
| 439 |
citations_network = gr.HTML("<h3>Citations Network Graph</h3>", visible=True, elem_id="papers-citations-network")
|
| 440 |
-
btn_citations_network.click(lambda: Modal(visible=True), None,
|
| 441 |
|
| 442 |
|
| 443 |
|
|
@@ -445,7 +453,62 @@ with gr.Blocks(title="Climate Q&A", css_paths=os.getcwd()+ "/style.css", theme=t
|
|
| 445 |
|
| 446 |
graphs_container = gr.HTML("<h2>There are no graphs to be displayed at the moment. Try asking another question.</h2>",elem_id="graphs-container")
|
| 447 |
current_graphs.change(lambda x : x, inputs=[current_graphs], outputs=[graphs_container])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 448 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 449 |
# with gr.Tab("OECD",elem_id = "tab-oecd",id = 6):
|
| 450 |
# oecd_indicator = "RIVER_FLOOD_RP100_POP_SH"
|
| 451 |
# oecd_topic = "climate"
|
|
@@ -460,7 +523,6 @@ with gr.Blocks(title="Climate Q&A", css_paths=os.getcwd()+ "/style.css", theme=t
|
|
| 460 |
# oecd_textbox = gr.HTML(iframe_html, show_label=False, elem_id="oecd-textbox")
|
| 461 |
|
| 462 |
|
| 463 |
-
|
| 464 |
|
| 465 |
|
| 466 |
#---------------------------------------------------------------------------------------
|
|
|
|
| 117 |
|
| 118 |
agent = make_graph_agent(llm=llm, vectorstore_ipcc=vectorstore, vectorstore_graphs=vectorstore_graphs, reranker=reranker)
|
| 119 |
|
| 120 |
+
def update_config_modal_visibility(config_open):
|
| 121 |
+
new_config_visibility_status = not config_open
|
| 122 |
+
return gr.update(visible=new_config_visibility_status), new_config_visibility_status
|
| 123 |
|
| 124 |
async def chat(query, history, audience, sources, reports, relevant_content_sources, search_only):
|
| 125 |
"""taking a query and a message history, use a pipeline (reformulation, retriever, answering) to yield a tuple of:
|
|
|
|
| 296 |
chat_completed_state = gr.State(0)
|
| 297 |
current_graphs = gr.State([])
|
| 298 |
saved_graphs = gr.State({})
|
| 299 |
+
config_open = gr.State(False)
|
| 300 |
|
| 301 |
|
| 302 |
with gr.Tab("ClimateQ&A"):
|
|
|
|
| 321 |
|
| 322 |
with gr.Row(elem_id = "input-message"):
|
| 323 |
textbox=gr.Textbox(placeholder="Ask me anything here!",show_label=False,scale=7,lines = 1,interactive = True,elem_id="input-textbox")
|
| 324 |
+
|
| 325 |
+
config_button = gr.Button("",elem_id="config-button")
|
| 326 |
+
# config_checkbox_button = gr.Checkbox(label = '⚙️', value="show",visible=True, interactive=True, elem_id="checkbox-config")
|
| 327 |
+
|
| 328 |
+
|
| 329 |
|
| 330 |
with gr.Column(scale=2, variant="panel",elem_id = "right-panel"):
|
| 331 |
|
|
|
|
| 357 |
|
| 358 |
samples.append(group_examples)
|
| 359 |
|
| 360 |
+
# with gr.Tab("Configuration", id = 10, ) as tab_config:
|
| 361 |
+
# # gr.Markdown("Reminders: You can talk in any language, ClimateQ&A is multi-lingual!")
|
|
|
|
| 362 |
|
| 363 |
+
# pass
|
| 364 |
|
| 365 |
+
# with gr.Row():
|
| 366 |
|
| 367 |
+
# dropdown_sources = gr.CheckboxGroup(
|
| 368 |
+
# ["IPCC", "IPBES","IPOS"],
|
| 369 |
+
# label="Select source",
|
| 370 |
+
# value=["IPCC"],
|
| 371 |
+
# interactive=True,
|
| 372 |
+
# )
|
| 373 |
+
# dropdown_external_sources = gr.CheckboxGroup(
|
| 374 |
+
# ["IPCC figures","OpenAlex", "OurWorldInData"],
|
| 375 |
+
# label="Select database to search for relevant content",
|
| 376 |
+
# value=["IPCC figures"],
|
| 377 |
+
# interactive=True,
|
| 378 |
+
# )
|
| 379 |
+
|
| 380 |
+
# dropdown_reports = gr.Dropdown(
|
| 381 |
+
# POSSIBLE_REPORTS,
|
| 382 |
+
# label="Or select specific reports",
|
| 383 |
+
# multiselect=True,
|
| 384 |
+
# value=None,
|
| 385 |
+
# interactive=True,
|
| 386 |
+
# )
|
| 387 |
+
|
| 388 |
+
# search_only = gr.Checkbox(label="Search only without chating", value=False, interactive=True, elem_id="checkbox-chat")
|
| 389 |
+
|
| 390 |
+
|
| 391 |
+
# dropdown_audience = gr.Dropdown(
|
| 392 |
+
# ["Children","General public","Experts"],
|
| 393 |
+
# label="Select audience",
|
| 394 |
+
# value="Experts",
|
| 395 |
+
# interactive=True,
|
| 396 |
+
# )
|
| 397 |
|
| 398 |
|
| 399 |
+
# after = gr.Slider(minimum=1950,maximum=2023,step=1,value=1960,label="Publication date",show_label=True,interactive=True,elem_id="date-papers", visible=False)
|
| 400 |
+
|
| 401 |
|
| 402 |
+
# output_query = gr.Textbox(label="Query used for retrieval",show_label = True,elem_id = "reformulated-query",lines = 2,interactive = False, visible= False)
|
| 403 |
+
# output_language = gr.Textbox(label="Language",show_label = True,elem_id = "language",lines = 1,interactive = False, visible= False)
|
| 404 |
|
| 405 |
|
| 406 |
+
# dropdown_external_sources.change(lambda x: gr.update(visible = True ) if "OpenAlex" in x else gr.update(visible=False) , inputs=[dropdown_external_sources], outputs=[after])
|
| 407 |
+
# # dropdown_external_sources.change(lambda x: gr.update(visible = True ) if "OpenAlex" in x else gr.update(visible=False) , inputs=[dropdown_external_sources], outputs=[after], visible=True)
|
| 408 |
|
| 409 |
|
| 410 |
with gr.Tab("Sources",elem_id = "tab-sources",id = 1) as tab_sources:
|
|
|
|
| 419 |
with gr.Tab("Figures",elem_id = "tab-figures",id = 3) as tab_figures:
|
| 420 |
sources_raw = gr.State()
|
| 421 |
|
| 422 |
+
with Modal(visible=False, elem_id="modal_figure_galery") as figure_modal:
|
| 423 |
gallery_component = gr.Gallery(object_fit='scale-down',elem_id="gallery-component", height="80vh")
|
| 424 |
|
| 425 |
show_full_size_figures = gr.Button("Show figures in full size",elem_id="show-figures",interactive=True)
|
| 426 |
+
show_full_size_figures.click(lambda : Modal(visible=True),None,figure_modal)
|
| 427 |
|
| 428 |
figures_cards = gr.HTML(show_label=False, elem_id="sources-figures")
|
| 429 |
|
|
|
|
| 443 |
|
| 444 |
btn_citations_network = gr.Button("Explore papers citations network")
|
| 445 |
# Fenêtre simulée pour le Citations Network
|
| 446 |
+
with Modal(visible=False) as papers_modal:
|
| 447 |
citations_network = gr.HTML("<h3>Citations Network Graph</h3>", visible=True, elem_id="papers-citations-network")
|
| 448 |
+
btn_citations_network.click(lambda: Modal(visible=True), None, papers_modal)
|
| 449 |
|
| 450 |
|
| 451 |
|
|
|
|
| 453 |
|
| 454 |
graphs_container = gr.HTML("<h2>There are no graphs to be displayed at the moment. Try asking another question.</h2>",elem_id="graphs-container")
|
| 455 |
current_graphs.change(lambda x : x, inputs=[current_graphs], outputs=[graphs_container])
|
| 456 |
+
|
| 457 |
+
with Modal(visible=False,elem_id="modal-config") as config_modal:
|
| 458 |
+
gr.Markdown("Reminders: You can talk in any language, ClimateQ&A is multi-lingual!")
|
| 459 |
+
|
| 460 |
+
|
| 461 |
+
with gr.Row():
|
| 462 |
+
|
| 463 |
+
dropdown_sources = gr.CheckboxGroup(
|
| 464 |
+
["IPCC", "IPBES","IPOS"],
|
| 465 |
+
label="Select source",
|
| 466 |
+
value=["IPCC"],
|
| 467 |
+
interactive=True,
|
| 468 |
+
)
|
| 469 |
+
dropdown_external_sources = gr.CheckboxGroup(
|
| 470 |
+
["IPCC figures","OpenAlex", "OurWorldInData"],
|
| 471 |
+
label="Select database to search for relevant content",
|
| 472 |
+
value=["IPCC figures"],
|
| 473 |
+
interactive=True,
|
| 474 |
+
)
|
| 475 |
+
|
| 476 |
+
dropdown_reports = gr.Dropdown(
|
| 477 |
+
POSSIBLE_REPORTS,
|
| 478 |
+
label="Or select specific reports",
|
| 479 |
+
multiselect=True,
|
| 480 |
+
value=None,
|
| 481 |
+
interactive=True,
|
| 482 |
+
)
|
| 483 |
+
|
| 484 |
+
search_only = gr.Checkbox(label="Search only without chating", value=False, interactive=True, elem_id="checkbox-chat")
|
| 485 |
+
|
| 486 |
|
| 487 |
+
dropdown_audience = gr.Dropdown(
|
| 488 |
+
["Children","General public","Experts"],
|
| 489 |
+
label="Select audience",
|
| 490 |
+
value="Experts",
|
| 491 |
+
interactive=True,
|
| 492 |
+
)
|
| 493 |
+
|
| 494 |
+
|
| 495 |
+
after = gr.Slider(minimum=1950,maximum=2023,step=1,value=1960,label="Publication date",show_label=True,interactive=True,elem_id="date-papers", visible=False)
|
| 496 |
+
|
| 497 |
+
|
| 498 |
+
output_query = gr.Textbox(label="Query used for retrieval",show_label = True,elem_id = "reformulated-query",lines = 2,interactive = False, visible= False)
|
| 499 |
+
output_language = gr.Textbox(label="Language",show_label = True,elem_id = "language",lines = 1,interactive = False, visible= False)
|
| 500 |
+
|
| 501 |
+
|
| 502 |
+
dropdown_external_sources.change(lambda x: gr.update(visible = True ) if "OpenAlex" in x else gr.update(visible=False) , inputs=[dropdown_external_sources], outputs=[after])
|
| 503 |
+
|
| 504 |
+
close_config_modal = gr.Button("Close",elem_id="close-config-modal")
|
| 505 |
+
close_config_modal.click(fn=update_config_modal_visibility, inputs=[config_open], outputs=[config_modal, config_open])
|
| 506 |
+
# dropdown_external_sources.change(lambda x: gr.update(visible = True ) if "OpenAlex" in x else gr.update(visible=False) , inputs=[dropdown_external_sources], outputs=[after], visible=True)
|
| 507 |
+
|
| 508 |
+
|
| 509 |
+
|
| 510 |
+
config_button.click(fn=update_config_modal_visibility, inputs=[config_open], outputs=[config_modal, config_open])
|
| 511 |
+
|
| 512 |
# with gr.Tab("OECD",elem_id = "tab-oecd",id = 6):
|
| 513 |
# oecd_indicator = "RIVER_FLOOD_RP100_POP_SH"
|
| 514 |
# oecd_topic = "climate"
|
|
|
|
| 523 |
# oecd_textbox = gr.HTML(iframe_html, show_label=False, elem_id="oecd-textbox")
|
| 524 |
|
| 525 |
|
|
|
|
| 526 |
|
| 527 |
|
| 528 |
#---------------------------------------------------------------------------------------
|
style.css
CHANGED
|
@@ -283,6 +283,95 @@ label.selected{
|
|
| 283 |
padding:0px !important;
|
| 284 |
}
|
| 285 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 286 |
@media screen and (min-width: 1024px) {
|
| 287 |
/* Additional style for scrollable tab content */
|
| 288 |
/* div#tab-recommended_content {
|
|
|
|
| 283 |
padding:0px !important;
|
| 284 |
}
|
| 285 |
|
| 286 |
+
#modal-config .block.modal-block.padded {
|
| 287 |
+
padding-top: 25px;
|
| 288 |
+
height: 100vh;
|
| 289 |
+
|
| 290 |
+
}
|
| 291 |
+
#modal-config .modal-container{
|
| 292 |
+
margin: 0px;
|
| 293 |
+
padding: 0px;
|
| 294 |
+
}
|
| 295 |
+
/* Modal styles */
|
| 296 |
+
#modal-config {
|
| 297 |
+
position: fixed;
|
| 298 |
+
top: 0;
|
| 299 |
+
left: 0;
|
| 300 |
+
height: 100vh;
|
| 301 |
+
width: 500px;
|
| 302 |
+
background-color: white;
|
| 303 |
+
box-shadow: 2px 0 10px rgba(0, 0, 0, 0.1);
|
| 304 |
+
z-index: 1000;
|
| 305 |
+
padding: 15px;
|
| 306 |
+
transform: none;
|
| 307 |
+
}
|
| 308 |
+
#modal-config .close{
|
| 309 |
+
display: none;
|
| 310 |
+
}
|
| 311 |
+
|
| 312 |
+
/* Push main content to the right when modal is open */
|
| 313 |
+
/* .modal ~ * {
|
| 314 |
+
margin-left: 300px;
|
| 315 |
+
transition: margin-left 0.3s ease;
|
| 316 |
+
} */
|
| 317 |
+
|
| 318 |
+
#modal-config .modal .wrap ul{
|
| 319 |
+
position:static;
|
| 320 |
+
top: 100%;
|
| 321 |
+
left: 0;
|
| 322 |
+
/* min-height: 100px; */
|
| 323 |
+
height: 100%;
|
| 324 |
+
/* margin-top: 0; */
|
| 325 |
+
z-index: 9999;
|
| 326 |
+
pointer-events: auto;
|
| 327 |
+
height: 200px;
|
| 328 |
+
}
|
| 329 |
+
#config-button{
|
| 330 |
+
background: none;
|
| 331 |
+
border: none;
|
| 332 |
+
padding: 8px;
|
| 333 |
+
cursor: pointer;
|
| 334 |
+
width: 40px;
|
| 335 |
+
height: 40px;
|
| 336 |
+
display: flex;
|
| 337 |
+
align-items: center;
|
| 338 |
+
justify-content: center;
|
| 339 |
+
border-radius: 50%;
|
| 340 |
+
transition: background-color 0.2s;
|
| 341 |
+
}
|
| 342 |
+
|
| 343 |
+
#config-button::before {
|
| 344 |
+
content: '⚙️';
|
| 345 |
+
font-size: 20px;
|
| 346 |
+
}
|
| 347 |
+
|
| 348 |
+
#config-button:hover {
|
| 349 |
+
background-color: rgba(0, 0, 0, 0.1);
|
| 350 |
+
}
|
| 351 |
+
|
| 352 |
+
#checkbox-config{
|
| 353 |
+
display: block;
|
| 354 |
+
position: absolute;
|
| 355 |
+
background: none;
|
| 356 |
+
border: none;
|
| 357 |
+
padding: 8px;
|
| 358 |
+
cursor: pointer;
|
| 359 |
+
width: 40px;
|
| 360 |
+
height: 40px;
|
| 361 |
+
display: flex;
|
| 362 |
+
align-items: center;
|
| 363 |
+
justify-content: center;
|
| 364 |
+
border-radius: 50%;
|
| 365 |
+
transition: background-color 0.2s;
|
| 366 |
+
font-size: 20px;
|
| 367 |
+
text-align: center;
|
| 368 |
+
}
|
| 369 |
+
#checkbox-config:checked{
|
| 370 |
+
display: block;
|
| 371 |
+
}
|
| 372 |
+
|
| 373 |
+
|
| 374 |
+
|
| 375 |
@media screen and (min-width: 1024px) {
|
| 376 |
/* Additional style for scrollable tab content */
|
| 377 |
/* div#tab-recommended_content {
|