Nina commited on
Commit
f3d1657
β€’
1 Parent(s): f144281

clean repo & add report selection

Browse files
Files changed (3) hide show
  1. app.py +32 -17
  2. background.png +2 -2
  3. background2.png +0 -0
app.py CHANGED
@@ -10,22 +10,12 @@ from datasets import Dataset
10
  import time
11
  from utils import is_climate_change_related, make_pairs, set_openai_api_key
12
 
13
- document_store = FAISSDocumentStore.load(
14
- index_path="./documents/climate_gpt.faiss",
15
- config_path="./documents/climate_gpt.json",
16
- )
17
 
18
  classifier = pipeline("zero-shot-classification", model="facebook/bart-large-mnli")
19
  system_template = {"role": os.environ["role"], "content": os.environ["content"]}
20
 
21
- dense = EmbeddingRetriever(
22
- document_store=document_store,
23
- embedding_model="sentence-transformers/multi-qa-mpnet-base-dot-v1",
24
- model_format="sentence_transformers",
25
- )
26
 
27
-
28
- def gen_conv(query: str, history=[system_template], ipcc=True):
29
  """return (answer:str, history:list[dict], sources:str)
30
 
31
  Args:
@@ -36,6 +26,23 @@ def gen_conv(query: str, history=[system_template], ipcc=True):
36
  Returns:
37
  _type_: _description_
38
  """
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
39
  retrieve = ipcc and is_climate_change_related(query, classifier)
40
 
41
  sources = ""
@@ -78,12 +85,22 @@ def gen_conv(query: str, history=[system_template], ipcc=True):
78
 
79
 
80
  # Gradio
81
- css_code = ".gradio-container {background-image: url('file=background2.png')}"
 
 
 
 
 
 
 
82
 
83
- with gr.Blocks(title="🌍 ClimateGPT Ekimetrics", css=css_code) as demo: # css=css_code
 
 
 
 
84
 
85
  openai.api_key = os.environ["api_key"]
86
- # gr.Markdown("# Climate GPT")
87
  gr.Markdown("### Welcome to Climate GPT 🌍 ! ")
88
  gr.Markdown(
89
  """
@@ -120,7 +137,7 @@ with gr.Blocks(title="🌍 ClimateGPT Ekimetrics", css=css_code) as demo: # css
120
 
121
  ask.submit(
122
  fn=gen_conv,
123
- inputs=[ask, state],
124
  outputs=[chatbot, state, sources_textbox],
125
  )
126
  with gr.Accordion("Add your personal openai api key", open=False):
@@ -133,6 +150,4 @@ with gr.Blocks(title="🌍 ClimateGPT Ekimetrics", css=css_code) as demo: # css
133
  openai_api_key_textbox.change(set_openai_api_key, inputs=[openai_api_key_textbox])
134
  openai_api_key_textbox.submit(set_openai_api_key, inputs=[openai_api_key_textbox])
135
 
136
- # img = gr.Image("Ekimetrics_Logo_Color.jpg")
137
-
138
  demo.launch()
 
10
  import time
11
  from utils import is_climate_change_related, make_pairs, set_openai_api_key
12
 
 
 
 
 
13
 
14
  classifier = pipeline("zero-shot-classification", model="facebook/bart-large-mnli")
15
  system_template = {"role": os.environ["role"], "content": os.environ["content"]}
16
 
 
 
 
 
 
17
 
18
+ def gen_conv(query: str, report_type, history=[system_template], ipcc=True):
 
19
  """return (answer:str, history:list[dict], sources:str)
20
 
21
  Args:
 
26
  Returns:
27
  _type_: _description_
28
  """
29
+ if report_type == "giec":
30
+ document_store = FAISSDocumentStore.load(
31
+ index_path="./documents/climate_gpt_only_giec.faiss",
32
+ config_path="./documents/climate_gpt_only_giec.json",
33
+ )
34
+ else:
35
+ document_store = FAISSDocumentStore.load(
36
+ index_path="./documents/climate_gpt.faiss",
37
+ config_path="./documents/climate_gpt.json",
38
+ )
39
+
40
+ dense = EmbeddingRetriever(
41
+ document_store=document_store,
42
+ embedding_model="sentence-transformers/multi-qa-mpnet-base-dot-v1",
43
+ model_format="sentence_transformers",
44
+ )
45
+
46
  retrieve = ipcc and is_climate_change_related(query, classifier)
47
 
48
  sources = ""
 
85
 
86
 
87
  # Gradio
88
+ css_code = ".gradio-container {background-image: url('file=background.png');background-position: top right}"
89
+
90
+ with gr.Blocks(title="🌍 ClimateGPT Ekimetrics", css=css_code) as demo:
91
+
92
+ document_store = FAISSDocumentStore.load(
93
+ index_path="./documents/climate_gpt.faiss",
94
+ config_path="./documents/climate_gpt.json",
95
+ )
96
 
97
+ dense = EmbeddingRetriever(
98
+ document_store=document_store,
99
+ embedding_model="sentence-transformers/multi-qa-mpnet-base-dot-v1",
100
+ model_format="sentence_transformers",
101
+ )
102
 
103
  openai.api_key = os.environ["api_key"]
 
104
  gr.Markdown("### Welcome to Climate GPT 🌍 ! ")
105
  gr.Markdown(
106
  """
 
137
 
138
  ask.submit(
139
  fn=gen_conv,
140
+ inputs=[ask, gr.inputs.Dropdown(["giec only", "all"], default="all"), state],
141
  outputs=[chatbot, state, sources_textbox],
142
  )
143
  with gr.Accordion("Add your personal openai api key", open=False):
 
150
  openai_api_key_textbox.change(set_openai_api_key, inputs=[openai_api_key_textbox])
151
  openai_api_key_textbox.submit(set_openai_api_key, inputs=[openai_api_key_textbox])
152
 
 
 
153
  demo.launch()
background.png CHANGED

Git LFS Details

  • SHA256: aa68beb6bb245e0e3de74b26998818317b6daecc03fee47923d5c62a7097e931
  • Pointer size: 132 Bytes
  • Size of remote file: 2.35 MB

Git LFS Details

  • SHA256: b432d3789fd4d7a3875f8bde0079839497920da941942a25b31676acb79795db
  • Pointer size: 130 Bytes
  • Size of remote file: 18.2 kB
background2.png DELETED
Binary file (18.2 kB)