NHZ commited on
Commit
477ae2a
·
verified ·
1 Parent(s): 91c2e41

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +44 -1
app.py CHANGED
@@ -70,5 +70,48 @@ def create_vector_store(text):
70
  st.title("RAG-based Application with Focused Context")
71
 
72
  # Predefined Google Drive link
73
- drive_url = "h
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
74
 
 
70
  st.title("RAG-based Application with Focused Context")
71
 
72
  # Predefined Google Drive link
73
+ drive_url = "https://drive.google.com/file/d/1XvqA1OIssRs2gbmOtKFKj-02yQ5X2yg0/view?usp=sharing"
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.from_chain_type(
106
+ retriever=retriever,
107
+ llm=llm,
108
+ chain_type="stuff", # Use the default chain type
109
+ return_source_documents=True # Optional
110
+ )
111
+
112
+ # Run the query through the QA chain
113
+ result = qa_chain.run(query)
114
+ st.write("Answer:", result)
115
+ else:
116
+ st.error("Failed to extract content from the document.")
117