Nina
commited on
Commit
Β·
0ecf863
1
Parent(s):
e32562e
clean repo & add report selection
Browse files- app.py +32 -17
- background.png +2 -2
- 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=
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 82 |
|
| 83 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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
|
|
Git LFS Details
|
background2.png
DELETED
|
Binary file (18.2 kB)
|
|
|