Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -70,46 +70,5 @@ def create_vector_store(text):
|
|
| 70 |
st.title("RAG-based Application with Focused Context")
|
| 71 |
|
| 72 |
# Predefined Google Drive link
|
| 73 |
-
drive_url = "
|
| 74 |
|
| 75 |
-
# Extract document content
|
| 76 |
-
st.write("Extracting content from the document...")
|
| 77 |
-
text = extract_pdf_content(drive_url)
|
| 78 |
-
if text:
|
| 79 |
-
st.write("Document extracted successfully!")
|
| 80 |
-
|
| 81 |
-
st.write("Creating vector store...")
|
| 82 |
-
vector_store, sentences = create_vector_store(text)
|
| 83 |
-
|
| 84 |
-
st.write("Vector store created successfully!")
|
| 85 |
-
|
| 86 |
-
query = st.text_input("Enter your query:")
|
| 87 |
-
if query:
|
| 88 |
-
st.write("Retrieving relevant context from the document...")
|
| 89 |
-
retriever = vector_store.as_retriever()
|
| 90 |
-
retriever.search_kwargs["k"] = 3 # Retrieve top 3 matches
|
| 91 |
-
|
| 92 |
-
# Define a prompt template to guide LLM response generation
|
| 93 |
-
prompt_template = PromptTemplate(
|
| 94 |
-
template="""
|
| 95 |
-
Use the following context to answer the question:
|
| 96 |
-
|
| 97 |
-
{context}
|
| 98 |
-
|
| 99 |
-
Question: {question}
|
| 100 |
-
Answer:""",
|
| 101 |
-
input_variables=["context", "question"]
|
| 102 |
-
)
|
| 103 |
-
|
| 104 |
-
# Create a RetrievalQA chain
|
| 105 |
-
qa_chain = RetrievalQA(
|
| 106 |
-
retriever=retriever,
|
| 107 |
-
llm=llm,
|
| 108 |
-
prompt=prompt_template
|
| 109 |
-
)
|
| 110 |
-
|
| 111 |
-
# Run the query through the QA chain
|
| 112 |
-
result = qa_chain.run(query)
|
| 113 |
-
st.write("Answer:", result)
|
| 114 |
-
else:
|
| 115 |
-
st.error("Failed to extract content from the document.")
|
|
|
|
| 70 |
st.title("RAG-based Application with Focused Context")
|
| 71 |
|
| 72 |
# Predefined Google Drive link
|
| 73 |
+
drive_url = "h
|
| 74 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|