SHAMIL SHAHBAZ AWAN commited on
Commit
6d92baa
·
verified ·
1 Parent(s): 3e42beb

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +54 -35
app.py CHANGED
@@ -18,6 +18,25 @@ st.markdown(
18
  background-repeat: no-repeat;
19
  }}
20
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
21
  /* Ensure title is black */
22
  h1 {{
23
  color: black !important; /* Force title color to black */
@@ -28,19 +47,6 @@ st.markdown(
28
  color: black; /* Set text color to black */
29
  }}
30
 
31
- /* Set footer styling */
32
- .footer {{
33
- position: fixed;
34
- bottom: 0;
35
- left: 0;
36
- right: 0;
37
- background-color: rgba(0, 0, 0, 0.6);
38
- color: white;
39
- text-align: center;
40
- padding: 10px 0;
41
- font-size: 14px;
42
- }}
43
-
44
  /* Set processing button color to green */
45
  .stButton button {{
46
  background-color: green;
@@ -139,7 +145,10 @@ def process_and_store_document(file_path):
139
  st.error(f"Error saving the FAISS index: {e}")
140
 
141
  # User interface for Streamlit
142
- st.title("Atomic Habits RAG Application")
 
 
 
143
 
144
  # Button to trigger document processing
145
  if st.button("Process PDF"):
@@ -149,27 +158,37 @@ if st.button("Process PDF"):
149
  user_query = st.text_input("Enter your query:")
150
 
151
  if user_query:
152
- # Generate embedding for the user query
153
- query_embedding = embedder.encode([user_query])
154
-
155
- # Perform the search on the FAISS index
156
- distances, indices = index.search(np.array(query_embedding), k=5)
157
-
158
- # Retrieve the most relevant chunks based on the indices
159
- retrieved_chunks = [chunks[idx] for idx in indices[0]]
160
-
161
- # Display the retrieved chunks
162
- st.subheader("Retrieved Chunks")
163
- for chunk in retrieved_chunks:
164
- st.write(chunk)
165
-
166
- # Combine the retrieved chunks with the query and generate a response using Groq
167
- combined_input = " ".join(retrieved_chunks) + user_query
168
- response = groq_client.generate(model="llama3-8b-8192", prompt=combined_input, max_tokens=200)
169
-
170
- # Display the generated response
171
- st.subheader("Generated Response")
172
- st.write(response["text"])
 
 
 
 
 
 
 
 
173
 
174
  # Footer
175
  st.markdown("<div class='footer'>Created by Shamil Shahbaz</div>", unsafe_allow_html=True)
 
 
 
18
  background-repeat: no-repeat;
19
  }}
20
 
21
+ /* Custom Top Bar */
22
+ .top-bar {{
23
+ position: fixed;
24
+ top: 0;
25
+ left: 0;
26
+ right: 0;
27
+ background-color: rgba(0, 0, 0, 0.6);
28
+ color: white;
29
+ text-align: center;
30
+ padding: 15px 0;
31
+ font-size: 24px;
32
+ z-index: 10;
33
+ }}
34
+
35
+ /* Content under the top bar */
36
+ .main-content {{
37
+ margin-top: 80px; /* To create space for the top bar */
38
+ }}
39
+
40
  /* Ensure title is black */
41
  h1 {{
42
  color: black !important; /* Force title color to black */
 
47
  color: black; /* Set text color to black */
48
  }}
49
 
 
 
 
 
 
 
 
 
 
 
 
 
 
50
  /* Set processing button color to green */
51
  .stButton button {{
52
  background-color: green;
 
145
  st.error(f"Error saving the FAISS index: {e}")
146
 
147
  # User interface for Streamlit
148
+ st.markdown('<div class="top-bar">Atomic Habits RAG Application</div>', unsafe_allow_html=True)
149
+
150
+ # Content under the top bar
151
+ st.markdown('<div class="main-content">', unsafe_allow_html=True)
152
 
153
  # Button to trigger document processing
154
  if st.button("Process PDF"):
 
158
  user_query = st.text_input("Enter your query:")
159
 
160
  if user_query:
161
+ # Check if there are any chunks in the index
162
+ if not chunks:
163
+ st.error("Please process the document first by clicking 'Process PDF'.")
164
+ else:
165
+ # Generate embedding for the user query
166
+ query_embedding = embedder.encode([user_query])
167
+
168
+ # Perform the search on the FAISS index
169
+ distances, indices = index.search(np.array(query_embedding), k=5)
170
+
171
+ # Check if the indices returned are valid
172
+ if indices.size == 0 or np.any(indices[0] == -1):
173
+ st.error("No relevant results found in the index.")
174
+ else:
175
+ # Retrieve the most relevant chunks based on the indices
176
+ retrieved_chunks = [chunks[idx] for idx in indices[0]]
177
+
178
+ # Display the retrieved chunks
179
+ st.subheader("Retrieved Chunks")
180
+ for chunk in retrieved_chunks:
181
+ st.write(chunk)
182
+
183
+ # Combine the retrieved chunks with the query and generate a response using Groq
184
+ combined_input = " ".join(retrieved_chunks) + user_query
185
+ response = groq_client.generate(model="llama3-8b-8192", prompt=combined_input, max_tokens=200)
186
+
187
+ # Display the generated response
188
+ st.subheader("Generated Response")
189
+ st.write(response["text"])
190
 
191
  # Footer
192
  st.markdown("<div class='footer'>Created by Shamil Shahbaz</div>", unsafe_allow_html=True)
193
+
194
+ st.markdown('</div>', unsafe_allow_html=True) # End the main content div