TheoLvs commited on
Commit
72c5fd8
1 Parent(s): ae04a40

Updated app with config and audiences

Browse files
Files changed (2) hide show
  1. app.py +32 -24
  2. style.css +7 -2
app.py CHANGED
@@ -136,7 +136,17 @@ def answer_user(message,history):
136
  return message, history + [[message, None]]
137
 
138
 
139
- def answer_bot(message,history):
 
 
 
 
 
 
 
 
 
 
140
  # history_langchain_format = []
141
  # for human, ai in history:
142
  # history_langchain_format.append(HumanMessage(content=human))
@@ -144,7 +154,7 @@ def answer_bot(message,history):
144
  # history_langchain_format.append(HumanMessage(content=message)
145
  # for next_token, content in stream(message):
146
  # yield(content)
147
- output = chain({"query":message,"audience":"expert climate scientist"})
148
  question = output["question"]
149
  sources = output["source_documents"]
150
 
@@ -337,7 +347,7 @@ with gr.Blocks(title="🌍 Climate Q&A", css="style.css", theme=theme) as demo:
337
  with gr.Row():
338
  with gr.Column(scale=2):
339
  # state = gr.State([system_template])
340
- bot = gr.Chatbot(height=400)
341
 
342
  with gr.Row():
343
  with gr.Column(scale = 7):
@@ -388,32 +398,35 @@ with gr.Blocks(title="🌍 Climate Q&A", css="style.css", theme=theme) as demo:
388
 
389
  with gr.Column(scale=1, variant="panel"):
390
 
391
- # dropdown_sources = gr.CheckboxGroup(
392
- # ["IPCC", "IPBES"],
393
- # label="Select reports",
394
- # value = ["IPCC"],
395
- # )
 
 
 
 
 
 
396
 
397
- # dropdown_audience = gr.Dropdown(
398
- # ["Children","Adult","Experts"],
399
- # label="Select audience",
400
- # value="Experts",
401
- # )
402
 
403
- gr.Markdown("### Sources")
404
- sources_textbox = gr.Markdown(show_label=False, elem_id="sources-textbox")
405
 
406
  # textbox.submit(predict_climateqa,[textbox,bot],[None,bot,sources_textbox])
407
 
408
  textbox.submit(answer_user, [textbox, bot], [textbox, bot], queue=False).then(
409
- answer_bot, [textbox,bot], [textbox,bot,sources_textbox]
410
  )
411
  examples_hidden.change(answer_user, [examples_hidden, bot], [textbox, bot], queue=False).then(
412
- answer_bot, [textbox,bot], [textbox,bot,sources_textbox]
413
  )
414
 
415
  submit_button.click(answer_user, [textbox, bot], [textbox, bot], queue=False).then(
416
- answer_bot, [textbox,bot], [textbox,bot,sources_textbox]
417
  )
418
 
419
 
@@ -448,12 +461,6 @@ with gr.Blocks(title="🌍 Climate Q&A", css="style.css", theme=theme) as demo:
448
  </div>
449
  ClimateQ&A harnesses modern OCR techniques to parse and preprocess IPCC reports. By leveraging state-of-the-art question-answering algorithms, <i>ClimateQ&A is able to sift through the extensive collection of climate scientific reports and identify relevant passages in response to user inquiries</i>. Furthermore, the integration of the ChatGPT API allows ClimateQ&A to present complex data in a user-friendly manner, summarizing key points and facilitating communication of climate science to a wider audience.
450
  </div>
451
-
452
- <div class="warning-box">
453
- Version 0.2-beta - This tool is under active development
454
- </div>
455
-
456
-
457
  """
458
  )
459
 
@@ -595,6 +602,7 @@ Or around 2 to 4 times more than a typical Google search.
595
  - Hugging Face version is finally up to date
596
  - Switched all python code to langchain codebase for cleaner code, easier maintenance and future features
597
  - Updated GPT model to August version
 
598
 
599
  ##### v1.0.0 - *2023-05-11*
600
  - First version of clean interface on https://climateqa.com
 
136
  return message, history + [[message, None]]
137
 
138
 
139
+ def answer_bot(message,history,audience):
140
+
141
+ if audience == "Children":
142
+ audience_prompt = audience_prompts["children"]
143
+ elif audience == "General public":
144
+ audience_prompt = audience_prompts["general"]
145
+ elif audience == "Experts":
146
+ audience_prompt = audience_prompts["expert"]
147
+ else:
148
+ audience_prompt = audience_prompts["expert"]
149
+
150
  # history_langchain_format = []
151
  # for human, ai in history:
152
  # history_langchain_format.append(HumanMessage(content=human))
 
154
  # history_langchain_format.append(HumanMessage(content=message)
155
  # for next_token, content in stream(message):
156
  # yield(content)
157
+ output = chain({"query":message,"audience":audience_prompt})
158
  question = output["question"]
159
  sources = output["source_documents"]
160
 
 
347
  with gr.Row():
348
  with gr.Column(scale=2):
349
  # state = gr.State([system_template])
350
+ bot = gr.Chatbot(height=400,show_copy_button=True,show_label = False)
351
 
352
  with gr.Row():
353
  with gr.Column(scale = 7):
 
398
 
399
  with gr.Column(scale=1, variant="panel"):
400
 
401
+ with gr.Tab("📚 Citations"):
402
+ sources_textbox = gr.Markdown(show_label=False, elem_id="sources-textbox")
403
+
404
+ with gr.Tab("⚙️ Configuration"):
405
+
406
+ gr.Markdown("Reminder: You can talk in any language, ClimateQ&A is multi-lingual!")
407
+
408
+ dropdown_sources = gr.CheckboxGroup(
409
+ ["IPCC", "IPBES"],
410
+ label="Select reports",
411
+ )
412
 
413
+ dropdown_audience = gr.Dropdown(
414
+ ["Children","General public","Experts"],
415
+ label="Select audience",
416
+ )
 
417
 
 
 
418
 
419
  # textbox.submit(predict_climateqa,[textbox,bot],[None,bot,sources_textbox])
420
 
421
  textbox.submit(answer_user, [textbox, bot], [textbox, bot], queue=False).then(
422
+ answer_bot, [textbox,bot,dropdown_audience], [textbox,bot,sources_textbox]
423
  )
424
  examples_hidden.change(answer_user, [examples_hidden, bot], [textbox, bot], queue=False).then(
425
+ answer_bot, [textbox,bot,dropdown_audience], [textbox,bot,sources_textbox]
426
  )
427
 
428
  submit_button.click(answer_user, [textbox, bot], [textbox, bot], queue=False).then(
429
+ answer_bot, [textbox,bot,dropdown_audience], [textbox,bot,sources_textbox]
430
  )
431
 
432
 
 
461
  </div>
462
  ClimateQ&A harnesses modern OCR techniques to parse and preprocess IPCC reports. By leveraging state-of-the-art question-answering algorithms, <i>ClimateQ&A is able to sift through the extensive collection of climate scientific reports and identify relevant passages in response to user inquiries</i>. Furthermore, the integration of the ChatGPT API allows ClimateQ&A to present complex data in a user-friendly manner, summarizing key points and facilitating communication of climate science to a wider audience.
463
  </div>
 
 
 
 
 
 
464
  """
465
  )
466
 
 
602
  - Hugging Face version is finally up to date
603
  - Switched all python code to langchain codebase for cleaner code, easier maintenance and future features
604
  - Updated GPT model to August version
605
+ - Use of HuggingFace embed on https://climateqa.com to avoid demultiplying deployments
606
 
607
  ##### v1.0.0 - *2023-05-11*
608
  - First version of clean interface on https://climateqa.com
style.css CHANGED
@@ -161,7 +161,12 @@ label > span{
161
  z-index: 10;
162
  }
163
  */
164
-
165
  label.selected{
166
  background:none !important;
167
- }
 
 
 
 
 
 
161
  z-index: 10;
162
  }
163
  */
164
+
165
  label.selected{
166
  background:none !important;
167
+ }
168
+
169
+ div#sources-textbox{
170
+ height:100vh;
171
+ overflow-y: auto;
172
+ }