Spaces:
Sleeping
Sleeping
SHAMIL SHAHBAZ AWAN
commited on
Update app.py
Browse files
app.py
CHANGED
|
@@ -6,7 +6,7 @@ import faiss
|
|
| 6 |
import numpy as np
|
| 7 |
from groq import Client
|
| 8 |
|
| 9 |
-
# Set background image and
|
| 10 |
background_image_url = "https://jamesclear.com/wp-content/uploads/2020/11/atomic-habits_gallery_hi-res_01.jpg"
|
| 11 |
st.markdown(
|
| 12 |
f"""
|
|
@@ -17,9 +17,12 @@ st.markdown(
|
|
| 17 |
background-position: center center;
|
| 18 |
background-repeat: no-repeat;
|
| 19 |
}}
|
|
|
|
| 20 |
h1, h2, h3, h4, h5, h6, p {{
|
| 21 |
color: black; /* Set text color to black */
|
| 22 |
}}
|
|
|
|
|
|
|
| 23 |
.footer {{
|
| 24 |
position: fixed;
|
| 25 |
bottom: 0;
|
|
@@ -31,6 +34,19 @@ st.markdown(
|
|
| 31 |
padding: 10px 0;
|
| 32 |
font-size: 14px;
|
| 33 |
}}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 34 |
</style>
|
| 35 |
""",
|
| 36 |
unsafe_allow_html=True
|
|
@@ -60,8 +76,14 @@ vectorstore_path = os.path.join(VECTORSTORE_FOLDER, "index.faiss") # Correct pa
|
|
| 60 |
|
| 61 |
# Load or create FAISS index
|
| 62 |
if os.path.exists(vectorstore_path):
|
| 63 |
-
index
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 64 |
else:
|
|
|
|
| 65 |
index = faiss.IndexFlatL2(embedder.get_sentence_embedding_dimension())
|
| 66 |
|
| 67 |
# Function to load text from PDF
|
|
@@ -99,9 +121,11 @@ def process_and_store_document(file_path):
|
|
| 99 |
index.add(np.array(embeddings))
|
| 100 |
|
| 101 |
# Save the updated FAISS index
|
| 102 |
-
|
| 103 |
-
|
| 104 |
-
|
|
|
|
|
|
|
| 105 |
|
| 106 |
# User interface for Streamlit
|
| 107 |
st.title("Atomic Habits RAG Application")
|
|
|
|
| 6 |
import numpy as np
|
| 7 |
from groq import Client
|
| 8 |
|
| 9 |
+
# Set background image and customize colors
|
| 10 |
background_image_url = "https://jamesclear.com/wp-content/uploads/2020/11/atomic-habits_gallery_hi-res_01.jpg"
|
| 11 |
st.markdown(
|
| 12 |
f"""
|
|
|
|
| 17 |
background-position: center center;
|
| 18 |
background-repeat: no-repeat;
|
| 19 |
}}
|
| 20 |
+
/* Set title and footer text color to black */
|
| 21 |
h1, h2, h3, h4, h5, h6, p {{
|
| 22 |
color: black; /* Set text color to black */
|
| 23 |
}}
|
| 24 |
+
|
| 25 |
+
/* Set footer styling */
|
| 26 |
.footer {{
|
| 27 |
position: fixed;
|
| 28 |
bottom: 0;
|
|
|
|
| 34 |
padding: 10px 0;
|
| 35 |
font-size: 14px;
|
| 36 |
}}
|
| 37 |
+
|
| 38 |
+
/* Set processing button color to green */
|
| 39 |
+
.stButton button {{
|
| 40 |
+
background-color: green;
|
| 41 |
+
color: white;
|
| 42 |
+
}}
|
| 43 |
+
|
| 44 |
+
/* Set query input block background color to white */
|
| 45 |
+
.stTextInput input {{
|
| 46 |
+
background-color: white;
|
| 47 |
+
color: black;
|
| 48 |
+
}}
|
| 49 |
+
|
| 50 |
</style>
|
| 51 |
""",
|
| 52 |
unsafe_allow_html=True
|
|
|
|
| 76 |
|
| 77 |
# Load or create FAISS index
|
| 78 |
if os.path.exists(vectorstore_path):
|
| 79 |
+
# If the index file exists, read it
|
| 80 |
+
try:
|
| 81 |
+
index = faiss.read_index(vectorstore_path)
|
| 82 |
+
except Exception as e:
|
| 83 |
+
st.error(f"Error reading the FAISS index: {e}")
|
| 84 |
+
index = faiss.IndexFlatL2(embedder.get_sentence_embedding_dimension())
|
| 85 |
else:
|
| 86 |
+
# If the index file doesn't exist, create a new one
|
| 87 |
index = faiss.IndexFlatL2(embedder.get_sentence_embedding_dimension())
|
| 88 |
|
| 89 |
# Function to load text from PDF
|
|
|
|
| 121 |
index.add(np.array(embeddings))
|
| 122 |
|
| 123 |
# Save the updated FAISS index
|
| 124 |
+
try:
|
| 125 |
+
faiss.write_index(index, vectorstore_path)
|
| 126 |
+
st.success("Document processed and vector store updated!")
|
| 127 |
+
except Exception as e:
|
| 128 |
+
st.error(f"Error saving the FAISS index: {e}")
|
| 129 |
|
| 130 |
# User interface for Streamlit
|
| 131 |
st.title("Atomic Habits RAG Application")
|