LOUIS SANNA commited on
Commit
942ee37
1 Parent(s): bb75389

feat(qa): update qa tab

Browse files
Files changed (1) hide show
  1. app.py +27 -60
app.py CHANGED
@@ -46,9 +46,8 @@ user_id = create_user_id()
46
  # ---------------------------------------------------------------------------
47
 
48
  from langchain.callbacks.base import BaseCallbackHandler
49
- from queue import Queue, Empty
50
  from threading import Thread
51
- from collections.abc import Generator
52
  from langchain.schema import LLMResult
53
  from typing import Any, Union, Dict, List
54
  from queue import SimpleQueue
@@ -170,7 +169,7 @@ def fetch_sources(query, sources):
170
  sources_text = (
171
  "⚠️ No relevant passages found in the scientific reports (IPCC and IPBES)"
172
  )
173
- citations_text = "**⚠️ No relevant passages found in the climate science reports (IPCC and IPBES), you may want to ask a more specific question (specifying your question on climate and biodiversity issues).**"
174
  docs_text = ""
175
  return "", citations_text, docs_text, question, language
176
 
@@ -249,7 +248,7 @@ def answer_bot(query, history, docs, question, language, audience):
249
  log(question=question, history=history, docs=docs, user_id=user_id)
250
 
251
  else:
252
- complete_response = "**⚠️ No relevant passages found in the climate science reports (IPCC and IPBES), you may want to ask a more specific question (specifying your question on climate and biodiversity issues).**"
253
  history[-1][1] += complete_response
254
  yield "", history
255
 
@@ -291,12 +290,12 @@ def reset_textbox():
291
 
292
 
293
  init_prompt = """
294
- Hello, I am ClimateQ&A, a conversational assistant designed to help you understand climate change and biodiversity loss. I will answer your questions by **sifting through the IPCC and IPBES scientific reports**.
295
 
296
  💡 How to use
297
  - **Language**: You can ask me your questions in any language.
298
  - **Audience**: You can specify your audience (children, general public, experts) to get a more adapted answer.
299
- - **Sources**: You can choose to search in the IPCC or IPBES reports, or both.
300
 
301
  ⚠️ Limitations
302
  *Please note that the AI is not perfect and may sometimes give irrelevant answers. If you are not satisfied with the answer, please ask a more specific question or report your feedback to help us improve the system.*
@@ -316,10 +315,10 @@ def change_tab():
316
  return gr.Tabs.update(selected=1)
317
 
318
 
319
- with gr.Blocks(title="🌍 Climate Q&A", css="style.css", theme=theme) as demo:
320
  # user_id_state = gr.State([user_id])
321
 
322
- with gr.Tab("🌍 ClimateQ&A"):
323
  with gr.Row(elem_id="chatbot-row"):
324
  with gr.Column(scale=2):
325
  # state = gr.State([system_template])
@@ -349,41 +348,21 @@ with gr.Blocks(title="🌍 Climate Q&A", css="style.css", theme=theme) as demo:
349
  with gr.TabItem("📝 Examples", elem_id="tab-examples", id=0):
350
  examples_hidden = gr.Textbox(elem_id="hidden-message")
351
 
 
 
 
 
 
 
 
 
 
 
 
 
 
352
  examples_questions = gr.Examples(
353
- [
354
- "Is climate change caused by humans?",
355
- "What evidence do we have of climate change?",
356
- "What are the impacts of climate change?",
357
- "Can climate change be reversed?",
358
- "What is the difference between climate change and global warming?",
359
- "What can individuals do to address climate change?",
360
- "What are the main causes of climate change?",
361
- "What is the Paris Agreement and why is it important?",
362
- "Which industries have the highest GHG emissions?",
363
- "Is climate change a hoax created by the government or environmental organizations?",
364
- "What is the relationship between climate change and biodiversity loss?",
365
- "What is the link between gender equality and climate change?",
366
- "Is the impact of climate change really as severe as it is claimed to be?",
367
- "What is the impact of rising sea levels?",
368
- "What are the different greenhouse gases (GHG)?",
369
- "What is the warming power of methane?",
370
- "What is the jet stream?",
371
- "What is the breakdown of carbon sinks?",
372
- "How do the GHGs work ? Why does temperature increase ?",
373
- "What is the impact of global warming on ocean currents?",
374
- "How much warming is possible in 2050?",
375
- "What is the impact of climate change in Africa?",
376
- "Will climate change accelerate diseases and epidemics like COVID?",
377
- "What are the economic impacts of climate change?",
378
- "How much is the cost of inaction ?",
379
- "What is the relationship between climate change and poverty?",
380
- "What are the most effective strategies and technologies for reducing greenhouse gas (GHG) emissions?",
381
- "Is economic growth possible? What do you think about degrowth?",
382
- "Will technology save us?",
383
- "Is climate change a natural phenomenon ?",
384
- "Is climate change really happening or is it just a natural fluctuation in Earth's temperature?",
385
- "Is the scientific consensus on climate change really as strong as it is claimed to be?",
386
- ],
387
  [examples_hidden],
388
  examples_per_page=10,
389
  run_on_click=False,
@@ -398,7 +377,7 @@ with gr.Blocks(title="🌍 Climate Q&A", css="style.css", theme=theme) as demo:
398
 
399
  with gr.Tab("⚙️ Configuration", elem_id="tab-config", id=2):
400
  gr.Markdown(
401
- "Reminder: You can talk in any language, ClimateQ&A is multi-lingual!"
402
  )
403
 
404
  dropdown_sources = gr.CheckboxGroup(
@@ -430,7 +409,6 @@ with gr.Blocks(title="🌍 Climate Q&A", css="style.css", theme=theme) as demo:
430
  interactive=False,
431
  )
432
 
433
- # textbox.submit(predict_climateqa,[textbox,bot],[None,bot,sources_textbox])
434
  (
435
  textbox.submit(
436
  answer_user,
@@ -500,9 +478,6 @@ with gr.Blocks(title="🌍 Climate Q&A", css="style.css", theme=theme) as demo:
500
  )
501
  .success(lambda x: textbox, [textbox], [textbox])
502
  )
503
- # submit_button.click(answer_user, [textbox, bot], [textbox, bot], queue=True).then(
504
- # answer_bot, [textbox,bot,dropdown_audience,dropdown_sources], [textbox,bot,sources_textbox]
505
- # )
506
 
507
  # ---------------------------------------------------------------------------------------
508
  # OTHER TABS
@@ -627,7 +602,7 @@ Carbon emissions were measured during the development and inference process usin
627
  | Inference | Question Answering | ~0.102gCO2e / call | CodeCarbon |
628
  | Inference | API call to turbo-GPT | ~0.38gCO2e / call | https://medium.com/@chrispointon/the-carbon-footprint-of-chatgpt-e1bc14e4cc2a |
629
 
630
- Carbon Emissions are **relatively low but not negligible** compared to other usages: one question asked to ClimateQ&A is around 0.482gCO2e - equivalent to 2.2m by car (https://datagir.ademe.fr/apps/impact-co2/)
631
  Or around 2 to 4 times more than a typical Google search.
632
  """
633
  )
@@ -636,18 +611,10 @@ Or around 2 to 4 times more than a typical Google search.
636
  gr.Markdown(
637
  """
638
 
639
- ##### v1.1.0 - *2023-10-16*
640
- - ClimateQ&A on Hugging Face is finally working again with all the new features !
641
- - Switched all python code to langchain codebase for cleaner code, easier maintenance and future features
642
- - Updated GPT model to August version
643
- - Added streaming response to improve UX
644
- - Created a custom Retriever chain to avoid calling the LLM if there is no documents retrieved
645
- - Use of HuggingFace embed on https://climateqa.com to avoid demultiplying deployments
646
-
647
- ##### v1.0.0 - *2023-05-11*
648
- - First version of clean interface on https://climateqa.com
649
- - Add children mode on https://climateqa.com
650
- - Add follow-up questions https://climateqa.com
651
  """
652
  )
653
 
 
46
  # ---------------------------------------------------------------------------
47
 
48
  from langchain.callbacks.base import BaseCallbackHandler
49
+ from queue import Empty
50
  from threading import Thread
 
51
  from langchain.schema import LLMResult
52
  from typing import Any, Union, Dict, List
53
  from queue import SimpleQueue
 
169
  sources_text = (
170
  "⚠️ No relevant passages found in the scientific reports (IPCC and IPBES)"
171
  )
172
+ citations_text = "**⚠️ No relevant passages found in the sources, you may want to ask a more specific question.**"
173
  docs_text = ""
174
  return "", citations_text, docs_text, question, language
175
 
 
248
  log(question=question, history=history, docs=docs, user_id=user_id)
249
 
250
  else:
251
+ complete_response = "**⚠️ No relevant passages found in the sources, you may want to ask a more specific question.**"
252
  history[-1][1] += complete_response
253
  yield "", history
254
 
 
290
 
291
 
292
  init_prompt = """
293
+ Hello, I'm a conversational assistant. I will answer your questions by **sifting through trusted data sources**.
294
 
295
  💡 How to use
296
  - **Language**: You can ask me your questions in any language.
297
  - **Audience**: You can specify your audience (children, general public, experts) to get a more adapted answer.
298
+ - **Sources**: You can choose to search in which sources you want me to look for answers. By default, I will search in all sources.
299
 
300
  ⚠️ Limitations
301
  *Please note that the AI is not perfect and may sometimes give irrelevant answers. If you are not satisfied with the answer, please ask a more specific question or report your feedback to help us improve the system.*
 
315
  return gr.Tabs.update(selected=1)
316
 
317
 
318
+ with gr.Blocks(title=" Q&A", css="style.css", theme=theme) as demo:
319
  # user_id_state = gr.State([user_id])
320
 
321
+ with gr.Tab(" Q&A"):
322
  with gr.Row(elem_id="chatbot-row"):
323
  with gr.Column(scale=2):
324
  # state = gr.State([system_template])
 
348
  with gr.TabItem("📝 Examples", elem_id="tab-examples", id=0):
349
  examples_hidden = gr.Textbox(elem_id="hidden-message")
350
 
351
+ questions = [
352
+ "How does doaism view our dependence on modern technology?",
353
+ "From a doaism perspective, should we embrace or challenge the rise of AI?",
354
+ "How might doaism influence sustainable economic practices?",
355
+ "Does doaism support the idea of a minimalistic economy over consumerism?",
356
+ "How does doaism interpret the dynamics of modern relationships?",
357
+ "From a doaism viewpoint, how should society handle conflicts and disagreements?",
358
+ "How might doaism guide our approach to mental and physical health?",
359
+ "Does doaism offer insights into balancing work-life pressures in the modern age?",
360
+ "How does doaism view the purpose and methods of modern education?",
361
+ "From a doaism perspective, should learning be more experiential than theoretical?",
362
+ ]
363
+
364
  examples_questions = gr.Examples(
365
+ questions,
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
366
  [examples_hidden],
367
  examples_per_page=10,
368
  run_on_click=False,
 
377
 
378
  with gr.Tab("⚙️ Configuration", elem_id="tab-config", id=2):
379
  gr.Markdown(
380
+ "Reminder: You can talk in any language, this tool is multi-lingual!"
381
  )
382
 
383
  dropdown_sources = gr.CheckboxGroup(
 
409
  interactive=False,
410
  )
411
 
 
412
  (
413
  textbox.submit(
414
  answer_user,
 
478
  )
479
  .success(lambda x: textbox, [textbox], [textbox])
480
  )
 
 
 
481
 
482
  # ---------------------------------------------------------------------------------------
483
  # OTHER TABS
 
602
  | Inference | Question Answering | ~0.102gCO2e / call | CodeCarbon |
603
  | Inference | API call to turbo-GPT | ~0.38gCO2e / call | https://medium.com/@chrispointon/the-carbon-footprint-of-chatgpt-e1bc14e4cc2a |
604
 
605
+ Carbon Emissions are **relatively low but not negligible** compared to other usages: one question asked is around 0.482gCO2e - equivalent to 2.2m by car (https://datagir.ademe.fr/apps/impact-co2/)
606
  Or around 2 to 4 times more than a typical Google search.
607
  """
608
  )
 
611
  gr.Markdown(
612
  """
613
 
614
+ ##### v1.0.0 - 2023-10-25
615
+
616
+ - Cloned from ClimateQ&A
617
+ - Added support for other topics
 
 
 
 
 
 
 
 
618
  """
619
  )
620