Spaces:
Build error
Build error
SHAMIL SHAHBAZ AWAN commited on
Update app.py
Browse files17 unmodified lines1819202122234 unmodified lines2829303132333435363738394041424344454692 unmodified lines1391401411421431441453 unmodified lines14915015115215315415515615715815916016116216316416516616716816917017117217317417517 unmodified linesbackground-repeat: no-repeat;}}/* Ensure title is black */h1 {{color: black !important; /* Force title color to black */4 unmodified linescolor: 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 linesst.error(f"Error saving the FAISS index: {e}")# User interface for Streamlitst.title("Atomic Habits RAG Application")# Button to trigger document processingif st.button("Process PDF"):3 unmodified linesuser_query = st.text_input("Enter your query:")if user_query:# Generate embedding for the user queryquery_embedding = embedder.encode([user_query])# Perform the search on the FAISS indexdistances, indices = index.search(np.array(query_embedding), k=5)# Retrieve the most relevant chunks based on the indicesretrieved_chunks = [chunks[idx] for idx in indices[0]]# Display the retrieved chunksst.subheader("Retrieved Chunks")for chunk in retrieved_chunks:st.write(chunk)# Combine the retrieved chunks with the query and generate a response using Groqcombined_input = " ".join(retrieved_chunks) + user_queryresponse = groq_client.generate(model="llama3-8b-8192", prompt=combined_input, max_tokens=200)# Display the generated responsest.subheader("Generated Response")st.write(response["text"])# Footerst.markdown("<div class='footer'>Created by Shamil Shahbaz</div>", unsafe_allow_html=True)17 unmodified lines181920212223242526272829303132333435363738394041424 unmodified lines47484950515292 unmodified lines1451461471481491501511521531543 unmodified lines15815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319417 unmodified linesbackground-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 linescolor: black; /* Set text color to black */}}/* Set processing button color to green */.stButton button {{background-color: green;92 unmodified linesst.error(f"Error saving the FAISS index: {e}")# User interface for Streamlitst.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 indexif not chunks:st.error("Please process the document first by clicking 'Process PDF'.")else:# Generate embedding for the user queryquery_embedding = embedder.encode([user_query])# Perform the search on the FAISS indexdistances, indices = index.search(np.array(query_embedding), k=5)# Check if the indices returned are validif 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 indicesretrieved_chunks = [chunks[idx] for idx in indices[0]]# Display the retrieved chunksst.subheader("Retrieved Chunks")for chunk in retrieved_chunks:st.write(chunk)# Combine the retrieved chunks with the query and generate a response using Groqcombined_input = " ".join(retrieved_chunks) + user_queryresponse = groq_client.generate(model="llama3-8b-8192", prompt=combined_input, max_tokens=200)# Display the generated responsest.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 div
app.py+54-35