var outside of func
Browse files
app.py
CHANGED
|
@@ -1,31 +1,28 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
from haystack.document_stores import FAISSDocumentStore
|
| 3 |
from haystack.nodes import EmbeddingRetriever
|
| 4 |
-
import numpy as np
|
| 5 |
import openai
|
| 6 |
import os
|
| 7 |
-
from datasets import load_dataset
|
| 8 |
-
from datasets import Dataset
|
| 9 |
-
import time
|
| 10 |
from utils import (
|
| 11 |
-
is_climate_change_related,
|
| 12 |
make_pairs,
|
| 13 |
set_openai_api_key,
|
| 14 |
get_random_string,
|
| 15 |
)
|
| 16 |
|
| 17 |
-
system_template = {"role":
|
| 18 |
-
|
| 19 |
-
|
| 20 |
only_ipcc_document_store = FAISSDocumentStore.load(
|
| 21 |
index_path="./documents/climate_gpt_only_giec.faiss",
|
| 22 |
config_path="./documents/climate_gpt_only_giec.json",
|
| 23 |
)
|
| 24 |
-
|
| 25 |
document_store = FAISSDocumentStore.load(
|
| 26 |
index_path="./documents/climate_gpt.faiss",
|
| 27 |
config_path="./documents/climate_gpt.json",
|
| 28 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 29 |
|
| 30 |
|
| 31 |
def gen_conv(query: str, history=[system_template], report_type="All available", threshold=0.56):
|
|
@@ -40,14 +37,8 @@ def gen_conv(query: str, history=[system_template], report_type="All available",
|
|
| 40 |
_type_: _description_
|
| 41 |
"""
|
| 42 |
|
| 43 |
-
dense = EmbeddingRetriever(
|
| 44 |
-
document_store=document_store if report_type == "All available" else only_ipcc_document_store,
|
| 45 |
-
embedding_model="sentence-transformers/multi-qa-mpnet-base-dot-v1",
|
| 46 |
-
model_format="sentence_transformers",
|
| 47 |
-
)
|
| 48 |
-
|
| 49 |
messages = history + [{"role": "user", "content": query}]
|
| 50 |
-
docs =
|
| 51 |
sources = "\n\n".join(
|
| 52 |
f"doc {i}: {d.meta['file_name']} page {d.meta['page_number']}\n{d.content}"
|
| 53 |
for i, d in enumerate(docs, 1)
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
from haystack.document_stores import FAISSDocumentStore
|
| 3 |
from haystack.nodes import EmbeddingRetriever
|
|
|
|
| 4 |
import openai
|
| 5 |
import os
|
|
|
|
|
|
|
|
|
|
| 6 |
from utils import (
|
|
|
|
| 7 |
make_pairs,
|
| 8 |
set_openai_api_key,
|
| 9 |
get_random_string,
|
| 10 |
)
|
| 11 |
|
| 12 |
+
system_template = {"role": "system", "content": os.environ["content"]}
|
|
|
|
|
|
|
| 13 |
only_ipcc_document_store = FAISSDocumentStore.load(
|
| 14 |
index_path="./documents/climate_gpt_only_giec.faiss",
|
| 15 |
config_path="./documents/climate_gpt_only_giec.json",
|
| 16 |
)
|
|
|
|
| 17 |
document_store = FAISSDocumentStore.load(
|
| 18 |
index_path="./documents/climate_gpt.faiss",
|
| 19 |
config_path="./documents/climate_gpt.json",
|
| 20 |
)
|
| 21 |
+
retriever = EmbeddingRetriever(
|
| 22 |
+
document_store=document_store if report_type == "All available" else only_ipcc_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], report_type="All available", threshold=0.56):
|
|
|
|
| 37 |
_type_: _description_
|
| 38 |
"""
|
| 39 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 40 |
messages = history + [{"role": "user", "content": query}]
|
| 41 |
+
docs = retriever.retrieve(query=query, top_k=10)
|
| 42 |
sources = "\n\n".join(
|
| 43 |
f"doc {i}: {d.meta['file_name']} page {d.meta['page_number']}\n{d.content}"
|
| 44 |
for i, d in enumerate(docs, 1)
|