Upload app_federal.py
Browse files- app_federal.py +15 -2
app_federal.py
CHANGED
@@ -26,6 +26,7 @@ from huggingface_hub import CommitScheduler
|
|
26 |
from ast import literal_eval
|
27 |
import re
|
28 |
import requests
|
|
|
29 |
|
30 |
|
31 |
def run_courtlistener_api(casename, citation, court):
|
@@ -276,7 +277,7 @@ def run_retrieval(query):
|
|
276 |
print ("query", query)
|
277 |
|
278 |
query_embeddings = run_dense_retrieval(query)
|
279 |
-
query_embeddings = pca_model.transform(query_embeddings)
|
280 |
D, I = faiss_index.search(query_embeddings, 100)
|
281 |
scores_embeddings = D[0]
|
282 |
indices_embeddings = I[0]
|
@@ -322,14 +323,26 @@ extractive_qa = pipeline("question-answering", model="ai-law-society-lab/extract
|
|
322 |
|
323 |
ds_paragraphs = load_dataset("ai-law-society-lab/federal-caselaw-paragraphs", token=os.getenv('hf_token'))["train"]
|
324 |
|
|
|
325 |
ds = load_dataset("ai-law-society-lab/federal-caselaw-embeddings-PCA-768", token=os.getenv('hf_token'))["train"]
|
326 |
ds = ds.with_format("np")
|
327 |
faiss_index = load_faiss_index(ds["embeddings"])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
328 |
|
|
|
329 |
|
|
|
|
|
330 |
with open('PCA_model.pkl', 'rb') as f:
|
331 |
pca_model = pickle.load(f)
|
332 |
-
|
333 |
|
334 |
with open("Federal_caselaw_metadata.json") as f:
|
335 |
metadata = json.load(f)
|
|
|
26 |
from ast import literal_eval
|
27 |
import re
|
28 |
import requests
|
29 |
+
#from huggingface_hub import hf_hub_download
|
30 |
|
31 |
|
32 |
def run_courtlistener_api(casename, citation, court):
|
|
|
277 |
print ("query", query)
|
278 |
|
279 |
query_embeddings = run_dense_retrieval(query)
|
280 |
+
#query_embeddings = pca_model.transform(query_embeddings)
|
281 |
D, I = faiss_index.search(query_embeddings, 100)
|
282 |
scores_embeddings = D[0]
|
283 |
indices_embeddings = I[0]
|
|
|
323 |
|
324 |
ds_paragraphs = load_dataset("ai-law-society-lab/federal-caselaw-paragraphs", token=os.getenv('hf_token'))["train"]
|
325 |
|
326 |
+
"""
|
327 |
ds = load_dataset("ai-law-society-lab/federal-caselaw-embeddings-PCA-768", token=os.getenv('hf_token'))["train"]
|
328 |
ds = ds.with_format("np")
|
329 |
faiss_index = load_faiss_index(ds["embeddings"])
|
330 |
+
"""
|
331 |
+
|
332 |
+
# repo_id = "ai-law-society-lab/save_OPD_project_output"
|
333 |
+
# url = "https://huggingface.co/datasets/ai-law-society-lab/save_OPD_project_output"
|
334 |
+
|
335 |
+
url = "https://huggingface.co/datasets/ai-law-society-lab/autofaiss-federal-index/"
|
336 |
+
faiss_index = "/Users/ds8100/Documents/NJ-caselaw-index/federal-index-faiss/knn.index"
|
337 |
+
file_path = hf_hub_download(repo_id=repo_id, filename="knn.index", repo_type="dataset", token=hf_token)
|
338 |
|
339 |
+
index = faiss.read_index(file_path)
|
340 |
|
341 |
+
|
342 |
+
"""
|
343 |
with open('PCA_model.pkl', 'rb') as f:
|
344 |
pca_model = pickle.load(f)
|
345 |
+
"""
|
346 |
|
347 |
with open("Federal_caselaw_metadata.json") as f:
|
348 |
metadata = json.load(f)
|