Spaces:
Build error
Build error
SHAMIL SHAHBAZ AWAN commited on
Update app.py
Browse files17 unmodified lines181920212223242526272829303132333435363738394041424 unmodified lines4748493132333435363738394041424350515292 unmodified lines1451461471421481491501511521531543 unmodified lines15815916016116216316416516616716815215315415515615715815916016116216316416516616716816917017117216917017117217317417517617717817918018118218318418518618718818919019119219319417 unmodified lines background-repeat: no-repeat; }} /* Custom Top Bar */ .top-bar {{ position: fixed; top: 0; left: 0; right: 0; background-color: rgba(0, 0, 0, 0.6); color: white; text-align: center; padding: 15px 0; font-size: 24px; z-index: 10; }}
/* Content under the top bar */ .main-content {{ margin-top: 80px; /* To create space for the top bar */ }} /* Ensure title is black */ h1 {{ color: black !important; /* Force title color to black */4 unmodified lines color: black; /* Set text color to black */ }} /* Set footer styling */ .footer {{ position: fixed; bottom: 0; left: 0; right: 0; background-color: rgba(0, 0, 0, 0.6); color: white; text-align: center; padding: 10px 0; font-size: 14px; }} /* Set processing button color to green */ .stButton button {{ background-color: green;92 unmodified lines st.error(f"Error saving the FAISS index: {e}")
# User interface for Streamlitst.title("Atomic Habits RAG Application")st.markdown('<div class="top-bar">Atomic Habits RAG Application</div>', unsafe_allow_html=True)
# Content under the top barst.markdown('<div class="main-content">', unsafe_allow_html=True)
# Button to trigger document processingif st.button("Process PDF"):3 unmodified linesuser_query = st.text_input("Enter your query:")
if user_query: # Check if there are any chunks in the index if not chunks: st.error("Please process the document first by clicking 'Process PDF'.") else: # Generate embedding for the user query query_embedding = embedder.encode([user_query]) # Perform the search on the FAISS index # Generate embedding for the user query query_embedding = embedder.encode([user_query]) # Perform the search on the FAISS index distances, indices = index.search(np.array(query_embedding), k=5) # Retrieve the most relevant chunks based on the indices retrieved_chunks = [chunks[idx] for idx in indices[0]] # Display the retrieved chunks st.subheader("Retrieved Chunks") for chunk in retrieved_chunks: st.write(chunk) # Combine the retrieved chunks with the query and generate a response using Groq combined_input = " ".join(retrieved_chunks) + user_query response = groq_client.generate(model="llama3-8b-8192", prompt=combined_input, max_tokens=200) # Display the generated response st.subheader("Generated Response") st.write(response["text"]) distances, indices = index.search(np.array(query_embedding), k=5) # Check if the indices returned are valid if indices.size == 0 or np.any(indices[0] == -1): st.error("No relevant results found in the index.") else: # Retrieve the most relevant chunks based on the indices retrieved_chunks = [chunks[idx] for idx in indices[0]] # Display the retrieved chunks st.subheader("Retrieved Chunks") for chunk in retrieved_chunks: st.write(chunk) # Combine the retrieved chunks with the query and generate a response using Groq combined_input = " ".join(retrieved_chunks) + user_query response = groq_client.generate(model="llama3-8b-8192", prompt=combined_input, max_tokens=200) # Display the generated response st.subheader("Generated Response") st.write(response["text"])
# Footerst.markdown("<div class='footer'>Created by Shamil Shahbaz</div>", unsafe_allow_html=True)
st.markdown('</div>', unsafe_allow_html=True) # End the main content divapp.py+54-35