Spaces:
Running
Running
Update app.py
Browse files
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 |
-
#
|
|
|
|
|
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 |
-
|
23 |
-
|
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")
|