Added switch tabs and raise errors
Browse files
app.py
CHANGED
@@ -146,6 +146,8 @@ from threading import Thread
|
|
146 |
import json
|
147 |
|
148 |
def answer_user(query,query_example,history):
|
|
|
|
|
149 |
return query, history + [[query, ". . ."]]
|
150 |
|
151 |
def answer_user_example(query,query_example,history):
|
@@ -474,6 +476,10 @@ def vote(data: gr.LikeData):
|
|
474 |
print(data)
|
475 |
|
476 |
|
|
|
|
|
|
|
|
|
477 |
with gr.Blocks(title="π Climate Q&A", css="style.css", theme=theme) as demo:
|
478 |
# user_id_state = gr.State([user_id])
|
479 |
|
@@ -497,96 +503,100 @@ with gr.Blocks(title="π Climate Q&A", css="style.css", theme=theme) as demo:
|
|
497 |
|
498 |
with gr.Column(scale=1, variant="panel",elem_id = "right-panel"):
|
499 |
|
500 |
-
|
501 |
-
|
502 |
-
|
503 |
-
|
504 |
-
|
505 |
-
|
506 |
-
|
507 |
-
|
508 |
-
|
509 |
-
|
510 |
-
|
511 |
-
|
512 |
-
|
513 |
-
|
514 |
-
|
515 |
-
|
516 |
-
|
517 |
-
|
518 |
-
|
519 |
-
|
520 |
-
|
521 |
-
|
522 |
-
|
523 |
-
|
524 |
-
|
525 |
-
|
526 |
-
|
527 |
-
|
528 |
-
|
529 |
-
|
530 |
-
|
531 |
-
|
532 |
-
|
533 |
-
|
534 |
-
|
535 |
-
|
536 |
-
|
537 |
-
|
538 |
-
|
539 |
-
|
540 |
-
|
541 |
-
|
542 |
-
|
543 |
-
|
544 |
-
|
545 |
-
|
546 |
-
|
547 |
-
|
548 |
-
|
549 |
-
|
550 |
-
|
551 |
-
|
552 |
-
|
553 |
-
|
554 |
-
|
555 |
-
|
556 |
-
|
557 |
-
|
558 |
-
|
559 |
-
|
560 |
-
|
561 |
-
|
562 |
-
|
563 |
-
|
564 |
-
|
565 |
-
|
566 |
-
|
567 |
-
|
568 |
-
|
569 |
-
|
570 |
-
|
571 |
-
|
572 |
-
|
573 |
-
|
574 |
-
|
575 |
-
.
|
576 |
-
|
577 |
-
|
578 |
-
|
579 |
-
|
580 |
-
|
581 |
-
|
582 |
-
|
583 |
-
|
584 |
-
|
585 |
-
|
586 |
-
|
587 |
-
|
588 |
-
|
589 |
-
|
|
|
|
|
|
|
|
|
590 |
|
591 |
|
592 |
|
|
|
146 |
import json
|
147 |
|
148 |
def answer_user(query,query_example,history):
|
149 |
+
if len(query) <= 2:
|
150 |
+
raise Exception("Please ask a longer question")
|
151 |
return query, history + [[query, ". . ."]]
|
152 |
|
153 |
def answer_user_example(query,query_example,history):
|
|
|
476 |
print(data)
|
477 |
|
478 |
|
479 |
+
def change_tab():
|
480 |
+
return gr.Tabs.update(selected=1)
|
481 |
+
|
482 |
+
|
483 |
with gr.Blocks(title="π Climate Q&A", css="style.css", theme=theme) as demo:
|
484 |
# user_id_state = gr.State([user_id])
|
485 |
|
|
|
503 |
|
504 |
with gr.Column(scale=1, variant="panel",elem_id = "right-panel"):
|
505 |
|
506 |
+
|
507 |
+
with gr.Tabs() as tabs:
|
508 |
+
with gr.TabItem("π Examples",elem_id = "tab-examples",id = 0):
|
509 |
+
|
510 |
+
examples_hidden = gr.Textbox(elem_id="hidden-message")
|
511 |
+
|
512 |
+
examples_questions = gr.Examples(
|
513 |
+
[
|
514 |
+
"Is climate change caused by humans?",
|
515 |
+
"What evidence do we have of climate change?",
|
516 |
+
"What are the impacts of climate change?",
|
517 |
+
"Can climate change be reversed?",
|
518 |
+
"What is the difference between climate change and global warming?",
|
519 |
+
"What can individuals do to address climate change?",
|
520 |
+
"What are the main causes of climate change?",
|
521 |
+
"What is the Paris Agreement and why is it important?",
|
522 |
+
"Which industries have the highest GHG emissions?",
|
523 |
+
"Is climate change a hoax created by the government or environmental organizations?",
|
524 |
+
"What is the relationship between climate change and biodiversity loss?",
|
525 |
+
"What is the link between gender equality and climate change?",
|
526 |
+
"Is the impact of climate change really as severe as it is claimed to be?",
|
527 |
+
"What is the impact of rising sea levels?",
|
528 |
+
"What are the different greenhouse gases (GHG)?",
|
529 |
+
"What is the warming power of methane?",
|
530 |
+
"What is the jet stream?",
|
531 |
+
"What is the breakdown of carbon sinks?",
|
532 |
+
"How do the GHGs work ? Why does temperature increase ?",
|
533 |
+
"What is the impact of global warming on ocean currents?",
|
534 |
+
"How much warming is possible in 2050?",
|
535 |
+
"What is the impact of climate change in Africa?",
|
536 |
+
"Will climate change accelerate diseases and epidemics like COVID?",
|
537 |
+
"What are the economic impacts of climate change?",
|
538 |
+
"How much is the cost of inaction ?",
|
539 |
+
"What is the relationship between climate change and poverty?",
|
540 |
+
"What are the most effective strategies and technologies for reducing greenhouse gas (GHG) emissions?",
|
541 |
+
"Is economic growth possible? What do you think about degrowth?",
|
542 |
+
"Will technology save us?",
|
543 |
+
"Is climate change a natural phenomenon ?",
|
544 |
+
"Is climate change really happening or is it just a natural fluctuation in Earth's temperature?",
|
545 |
+
"Is the scientific consensus on climate change really as strong as it is claimed to be?",
|
546 |
+
],
|
547 |
+
[examples_hidden],
|
548 |
+
examples_per_page=10,
|
549 |
+
run_on_click=False,
|
550 |
+
# cache_examples=True,
|
551 |
+
)
|
552 |
+
|
553 |
+
with gr.Tab("π Citations",elem_id = "tab-citations",id = 1):
|
554 |
+
sources_textbox = gr.HTML(show_label=False, elem_id="sources-textbox")
|
555 |
+
docs_textbox = gr.State("")
|
556 |
+
|
557 |
+
with gr.Tab("βοΈ Configuration",elem_id = "tab-config",id = 2):
|
558 |
+
|
559 |
+
gr.Markdown("Reminder: You can talk in any language, ClimateQ&A is multi-lingual!")
|
560 |
+
|
561 |
+
|
562 |
+
dropdown_sources = gr.CheckboxGroup(
|
563 |
+
["IPCC", "IPBES"],
|
564 |
+
label="Select reports",
|
565 |
+
value=["IPCC"],
|
566 |
+
interactive=True,
|
567 |
+
)
|
568 |
+
|
569 |
+
dropdown_audience = gr.Dropdown(
|
570 |
+
["Children","General public","Experts"],
|
571 |
+
label="Select audience",
|
572 |
+
value="Experts",
|
573 |
+
interactive=True,
|
574 |
+
)
|
575 |
+
|
576 |
+
output_query = gr.Textbox(label="Query used for retrieval",show_label = True,elem_id = "reformulated-query",lines = 2,interactive = False)
|
577 |
+
output_language = gr.Textbox(label="Language",show_label = True,elem_id = "language",lines = 1,interactive = False)
|
578 |
+
|
579 |
+
|
580 |
+
|
581 |
+
# textbox.submit(predict_climateqa,[textbox,bot],[None,bot,sources_textbox])
|
582 |
+
(textbox
|
583 |
+
.submit(answer_user, [textbox,examples_hidden, bot], [textbox, bot],queue = False)
|
584 |
+
.success(change_tab,None,tabs)
|
585 |
+
.success(fetch_sources,[textbox,dropdown_sources], [textbox,sources_textbox,docs_textbox,output_query,output_language])
|
586 |
+
.success(answer_bot, [textbox,bot,docs_textbox,output_query,output_language,dropdown_audience], [textbox,bot],queue = True)
|
587 |
+
.success(lambda x : textbox,[textbox],[textbox])
|
588 |
+
)
|
589 |
+
|
590 |
+
(examples_hidden
|
591 |
+
.change(answer_user_example, [textbox,examples_hidden, bot], [textbox, bot],queue = False)
|
592 |
+
.success(change_tab,None,tabs)
|
593 |
+
.success(fetch_sources,[textbox,dropdown_sources], [textbox,sources_textbox,docs_textbox,output_query,output_language])
|
594 |
+
.success(answer_bot, [textbox,bot,docs_textbox,output_query,output_language,dropdown_audience], [textbox,bot],queue=True)
|
595 |
+
.success(lambda x : textbox,[textbox],[textbox])
|
596 |
+
)
|
597 |
+
# submit_button.click(answer_user, [textbox, bot], [textbox, bot], queue=True).then(
|
598 |
+
# answer_bot, [textbox,bot,dropdown_audience,dropdown_sources], [textbox,bot,sources_textbox]
|
599 |
+
# )
|
600 |
|
601 |
|
602 |
|