Maxx0 commited on
Commit
f4aa6a9
·
1 Parent(s): b47616b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -11
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 chainlit as cl
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
- # Chainlit Function for Handling Messages
74
- @cl.on_message
75
- async def handle_message(message: cl.Message):
76
- query_text = message.content # Extract the text content from the message
77
- response = await cl.make_async(rag_pipeline.run)(query=query_text)
78
- answer = response["answers"][0].answer if response["answers"] else "No answer found."
79
- await cl.Message(author="Mprofier", content=answer).send()
 
 
80
 
81
- # Start the Chainlit application
82
  if __name__ == "__main__":
83
- cl.run()
 
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()