Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,7 +1,7 @@
|
|
1 |
-
|
2 |
import os
|
3 |
import time
|
4 |
import streamlit as st
|
|
|
5 |
from langchain_community.vectorstores import FAISS
|
6 |
from langchain_community.embeddings import HuggingFaceEmbeddings
|
7 |
from langchain.prompts import PromptTemplate
|
@@ -15,7 +15,7 @@ st.set_page_config(page_title="BharatLAW", layout="centered")
|
|
15 |
# Display logo
|
16 |
col1, col2, col3 = st.columns([1, 30, 1])
|
17 |
with col2:
|
18 |
-
st.image("https://github.com/
|
19 |
|
20 |
# Hide hamburger and default footer
|
21 |
def hide_hamburger_menu():
|
@@ -41,15 +41,25 @@ def load_embeddings():
|
|
41 |
|
42 |
embeddings = load_embeddings()
|
43 |
|
44 |
-
# β
|
45 |
index_dir = "ipc_embed_db"
|
46 |
index_faiss = os.path.join(index_dir, "index.faiss")
|
47 |
index_pkl = os.path.join(index_dir, "index.pkl")
|
48 |
|
49 |
-
if os.path.exists(index_faiss) and os.path.exists(index_pkl):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
50 |
db = FAISS.load_local(index_dir, embeddings, allow_dangerous_deserialization=True)
|
51 |
-
|
52 |
-
st.error("β
|
53 |
st.stop()
|
54 |
|
55 |
db_retriever = db.as_retriever(search_type="similarity", search_kwargs={"k": 3})
|
|
|
|
|
1 |
import os
|
2 |
import time
|
3 |
import streamlit as st
|
4 |
+
import subprocess
|
5 |
from langchain_community.vectorstores import FAISS
|
6 |
from langchain_community.embeddings import HuggingFaceEmbeddings
|
7 |
from langchain.prompts import PromptTemplate
|
|
|
15 |
# Display logo
|
16 |
col1, col2, col3 = st.columns([1, 30, 1])
|
17 |
with col2:
|
18 |
+
st.image("https://github.com/xadarsh/BharatLaw/blob/main/images/banner.png?raw=true", use_container_width=True)
|
19 |
|
20 |
# Hide hamburger and default footer
|
21 |
def hide_hamburger_menu():
|
|
|
41 |
|
42 |
embeddings = load_embeddings()
|
43 |
|
44 |
+
# β
Ensure FAISS index is built if missing
|
45 |
index_dir = "ipc_embed_db"
|
46 |
index_faiss = os.path.join(index_dir, "index.faiss")
|
47 |
index_pkl = os.path.join(index_dir, "index.pkl")
|
48 |
|
49 |
+
if not (os.path.exists(index_faiss) and os.path.exists(index_pkl)):
|
50 |
+
st.warning("β οΈ FAISS index files missing. Attempting to create them using `Ingest.py`...")
|
51 |
+
try:
|
52 |
+
subprocess.run(["python", "Ingest.py"], check=True)
|
53 |
+
st.success("β
FAISS index successfully created.")
|
54 |
+
except subprocess.CalledProcessError as e:
|
55 |
+
st.error(f"β Failed to create FAISS index.\n\n**Error**: {e}")
|
56 |
+
st.stop()
|
57 |
+
|
58 |
+
# β
Load FAISS index
|
59 |
+
try:
|
60 |
db = FAISS.load_local(index_dir, embeddings, allow_dangerous_deserialization=True)
|
61 |
+
except Exception as e:
|
62 |
+
st.error(f"β Could not load FAISS index even after attempting to build it.\n\n**Reason**: {str(e)}")
|
63 |
st.stop()
|
64 |
|
65 |
db_retriever = db.as_retriever(search_type="similarity", search_kwargs={"k": 3})
|