NEXAS commited on
Commit
6e1201a
Β·
verified Β·
1 Parent(s): 8e5c781

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -11
app.py CHANGED
@@ -5,7 +5,6 @@ from utils.ingestion import DocumentProcessor
5
  from utils.llm import LLMProcessor
6
  from utils.qa import QAEngine
7
 
8
- # Set up Streamlit page
9
  st.set_page_config(page_title="AI-Powered Document QA", layout="wide")
10
  st.title("πŸ“„ AI-Powered Document QA")
11
 
@@ -14,24 +13,23 @@ document_processor = DocumentProcessor()
14
  llm_processor = LLMProcessor()
15
  qa_engine = QAEngine()
16
 
17
- # File uploader
 
 
18
  st.sidebar.header("Upload a PDF")
19
  uploaded_file = st.sidebar.file_uploader("Choose a PDF file", type=["pdf"])
20
 
21
  if uploaded_file:
22
- # Save file to a temporary path
23
- pdf_path = f"temp/{uploaded_file.name}"
24
- os.makedirs("temp", exist_ok=True)
25
-
26
  with open(pdf_path, "wb") as f:
27
  f.write(uploaded_file.read())
28
 
29
  st.sidebar.success("βœ… File uploaded successfully!")
30
 
31
- # Process the document
32
  with st.spinner("πŸ”„ Processing document..."):
33
  document_processor.process_document(pdf_path)
34
-
35
  st.sidebar.success("βœ… Document processed successfully!")
36
 
37
  # Query input
@@ -41,13 +39,11 @@ if uploaded_file:
41
  if question:
42
  with st.spinner("🧠 Searching for relevant context..."):
43
  answer = qa_engine.query(question)
44
-
45
  st.subheader("πŸ“ Answer:")
46
  st.write(answer)
47
-
48
  else:
49
  st.warning("⚠️ Please enter a question.")
50
 
51
- # Footer
52
  st.markdown("---")
53
  st.caption("πŸ€– Powered by ChromaDB + Groq LLM | Built with ❀️ using Streamlit")
 
5
  from utils.llm import LLMProcessor
6
  from utils.qa import QAEngine
7
 
 
8
  st.set_page_config(page_title="AI-Powered Document QA", layout="wide")
9
  st.title("πŸ“„ AI-Powered Document QA")
10
 
 
13
  llm_processor = LLMProcessor()
14
  qa_engine = QAEngine()
15
 
16
+ # Ensure temp directory exists
17
+ os.makedirs("temp", exist_ok=True)
18
+
19
  st.sidebar.header("Upload a PDF")
20
  uploaded_file = st.sidebar.file_uploader("Choose a PDF file", type=["pdf"])
21
 
22
  if uploaded_file:
23
+ pdf_path = os.path.join("temp", uploaded_file.name)
24
+
 
 
25
  with open(pdf_path, "wb") as f:
26
  f.write(uploaded_file.read())
27
 
28
  st.sidebar.success("βœ… File uploaded successfully!")
29
 
 
30
  with st.spinner("πŸ”„ Processing document..."):
31
  document_processor.process_document(pdf_path)
32
+
33
  st.sidebar.success("βœ… Document processed successfully!")
34
 
35
  # Query input
 
39
  if question:
40
  with st.spinner("🧠 Searching for relevant context..."):
41
  answer = qa_engine.query(question)
42
+
43
  st.subheader("πŸ“ Answer:")
44
  st.write(answer)
 
45
  else:
46
  st.warning("⚠️ Please enter a question.")
47
 
 
48
  st.markdown("---")
49
  st.caption("πŸ€– Powered by ChromaDB + Groq LLM | Built with ❀️ using Streamlit")