Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -6,7 +6,7 @@ from haystack.document_stores import InMemoryDocumentStore
|
|
6 |
from haystack import Document, Pipeline
|
7 |
from haystack.nodes import BM25Retriever
|
8 |
from pprint import pprint
|
9 |
-
import
|
10 |
import logging
|
11 |
from dotenv import load_dotenv
|
12 |
load_dotenv()
|
@@ -25,7 +25,7 @@ def extract_text_from_pdf(pdf_path):
|
|
25 |
return text
|
26 |
|
27 |
# Extract text from the PDF file
|
28 |
-
pdf_file_path = "Data/MR. MPROFY.pdf"
|
29 |
pdf_text = extract_text_from_pdf(pdf_file_path)
|
30 |
if not pdf_text:
|
31 |
raise ValueError("No text extracted from PDF.")
|
@@ -70,14 +70,16 @@ rag_pipeline = Pipeline()
|
|
70 |
rag_pipeline.add_node(component=retriever, name="retriever", inputs=["Query"])
|
71 |
rag_pipeline.add_node(component=prompt_node, name="prompt_node", inputs=["retriever"])
|
72 |
|
73 |
-
#
|
74 |
-
|
75 |
-
|
76 |
-
query_text =
|
77 |
-
|
78 |
-
|
79 |
-
|
|
|
|
|
80 |
|
81 |
-
# Start the
|
82 |
if __name__ == "__main__":
|
83 |
-
|
|
|
6 |
from haystack import Document, Pipeline
|
7 |
from haystack.nodes import BM25Retriever
|
8 |
from pprint import pprint
|
9 |
+
import streamlit as st
|
10 |
import logging
|
11 |
from dotenv import load_dotenv
|
12 |
load_dotenv()
|
|
|
25 |
return text
|
26 |
|
27 |
# Extract text from the PDF file
|
28 |
+
pdf_file_path = "Data/MR. MPROFY.pdf"
|
29 |
pdf_text = extract_text_from_pdf(pdf_file_path)
|
30 |
if not pdf_text:
|
31 |
raise ValueError("No text extracted from PDF.")
|
|
|
70 |
rag_pipeline.add_node(component=retriever, name="retriever", inputs=["Query"])
|
71 |
rag_pipeline.add_node(component=prompt_node, name="prompt_node", inputs=["retriever"])
|
72 |
|
73 |
+
# Streamlit Function for Handling Input and Displaying Output
|
74 |
+
def run_streamlit_app():
|
75 |
+
st.title("Mprofier - AI Assistant")
|
76 |
+
query_text = st.text_input("Enter your question:")
|
77 |
+
|
78 |
+
if st.button("Get Answer"):
|
79 |
+
response = rag_pipeline.run(query=query_text)
|
80 |
+
answer = response["answers"][0].answer if response["answers"] else "No answer found."
|
81 |
+
st.write(answer)
|
82 |
|
83 |
+
# Start the Streamlit application
|
84 |
if __name__ == "__main__":
|
85 |
+
run_streamlit_app()
|