Spaces:
Sleeping
Sleeping
SHAMIL SHAHBAZ AWAN
commited on
Update app.py
Browse files
app.py
CHANGED
|
@@ -7,7 +7,7 @@ import numpy as np
|
|
| 7 |
from groq import Client
|
| 8 |
|
| 9 |
# Set background image and customize colors
|
| 10 |
-
background_image_url = "https://
|
| 11 |
st.markdown(
|
| 12 |
f"""
|
| 13 |
<style>
|
|
@@ -18,25 +18,6 @@ st.markdown(
|
|
| 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,6 +28,19 @@ st.markdown(
|
|
| 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,10 +139,7 @@ def process_and_store_document(file_path):
|
|
| 145 |
st.error(f"Error saving the FAISS index: {e}")
|
| 146 |
|
| 147 |
# User interface for Streamlit
|
| 148 |
-
st.
|
| 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"):
|
|
@@ -172,23 +163,27 @@ if user_query:
|
|
| 172 |
if indices.size == 0 or np.any(indices[0] == -1):
|
| 173 |
st.error("No relevant results found in the index.")
|
| 174 |
else:
|
| 175 |
-
#
|
| 176 |
-
|
| 177 |
-
|
| 178 |
-
# Display the retrieved chunks
|
| 179 |
-
st.subheader("Retrieved Chunks")
|
| 180 |
-
for chunk in retrieved_chunks:
|
| 181 |
-
st.write(chunk)
|
| 182 |
|
| 183 |
-
|
| 184 |
-
|
| 185 |
-
|
| 186 |
-
|
| 187 |
-
|
| 188 |
-
|
| 189 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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
|
|
|
|
| 7 |
from groq import Client
|
| 8 |
|
| 9 |
# Set background image and customize colors
|
| 10 |
+
background_image_url = "https://www.shutterstock.com/image-vector/artificial-intelligence-circuit-electric-line-600nw-2465096659.jpg"
|
| 11 |
st.markdown(
|
| 12 |
f"""
|
| 13 |
<style>
|
|
|
|
| 18 |
background-repeat: no-repeat;
|
| 19 |
}}
|
| 20 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 21 |
/* Ensure title is black */
|
| 22 |
h1 {{
|
| 23 |
color: black !important; /* Force title color to black */
|
|
|
|
| 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 |
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"):
|
|
|
|
| 163 |
if indices.size == 0 or np.any(indices[0] == -1):
|
| 164 |
st.error("No relevant results found in the index.")
|
| 165 |
else:
|
| 166 |
+
# Ensure indices are within the bounds of the chunks list
|
| 167 |
+
valid_indices = [idx for idx in indices[0] if idx < len(chunks)]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 168 |
|
| 169 |
+
if not valid_indices:
|
| 170 |
+
st.error("No valid indices found for the retrieved chunks.")
|
| 171 |
+
else:
|
| 172 |
+
# Retrieve the most relevant chunks based on the valid indices
|
| 173 |
+
retrieved_chunks = [chunks[idx] for idx in valid_indices]
|
| 174 |
+
|
| 175 |
+
# Display the retrieved chunks
|
| 176 |
+
st.subheader("Retrieved Chunks")
|
| 177 |
+
for chunk in retrieved_chunks:
|
| 178 |
+
st.write(chunk)
|
| 179 |
+
|
| 180 |
+
# Combine the retrieved chunks with the query and generate a response using Groq
|
| 181 |
+
combined_input = " ".join(retrieved_chunks) + user_query
|
| 182 |
+
response = groq_client.generate(model="llama3-8b-8192", prompt=combined_input, max_tokens=200)
|
| 183 |
+
|
| 184 |
+
# Display the generated response
|
| 185 |
+
st.subheader("Generated Response")
|
| 186 |
+
st.write(response["text"])
|
| 187 |
|
| 188 |
# Footer
|
| 189 |
st.markdown("<div class='footer'>Created by Shamil Shahbaz</div>", unsafe_allow_html=True)
|
|
|
|
|
|