Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -1,53 +1,53 @@
|
|
1 |
-
import streamlit as st
|
2 |
-
import os
|
3 |
-
import json
|
4 |
-
from ingestion import DocumentProcessor
|
5 |
-
from llm import LLMProcessor
|
6 |
-
from qa_engine 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 |
-
|
12 |
-
# Initialize processors
|
13 |
-
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
|
38 |
-
question = st.text_input("Ask a question from the document:", placeholder="What are the key insights?")
|
39 |
-
|
40 |
-
if st.button("π Search & Answer"):
|
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")
|
|
|
1 |
+
import streamlit as st
|
2 |
+
import os
|
3 |
+
import json
|
4 |
+
from utils.ingestion import DocumentProcessor
|
5 |
+
from utils.llm import LLMProcessor
|
6 |
+
from utils.qa_engine 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 |
+
|
12 |
+
# Initialize processors
|
13 |
+
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
|
38 |
+
question = st.text_input("Ask a question from the document:", placeholder="What are the key insights?")
|
39 |
+
|
40 |
+
if st.button("π Search & Answer"):
|
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")
|