Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,11 +1,12 @@
|
|
| 1 |
import streamlit as st
|
| 2 |
import os
|
|
|
|
| 3 |
from utils.ingestion import DocumentProcessor
|
| 4 |
from utils.llm import LLMProcessor
|
| 5 |
from utils.qa import QAEngine
|
| 6 |
|
| 7 |
-
|
| 8 |
-
st.
|
| 9 |
|
| 10 |
# Initialize processors
|
| 11 |
document_processor = DocumentProcessor()
|
|
@@ -15,7 +16,6 @@ qa_engine = QAEngine()
|
|
| 15 |
# Ensure temp directory exists
|
| 16 |
os.makedirs("temp", exist_ok=True)
|
| 17 |
|
| 18 |
-
# Sidebar - File Upload
|
| 19 |
st.sidebar.header("Upload a PDF")
|
| 20 |
uploaded_file = st.sidebar.file_uploader("Choose a PDF file", type=["pdf"])
|
| 21 |
|
|
@@ -27,40 +27,23 @@ if uploaded_file:
|
|
| 27 |
|
| 28 |
st.sidebar.success("β
File uploaded successfully!")
|
| 29 |
|
| 30 |
-
with st.spinner(""):
|
| 31 |
document_processor.process_document(pdf_path)
|
| 32 |
|
| 33 |
st.sidebar.success("β
Document processed successfully!")
|
| 34 |
|
| 35 |
-
#
|
| 36 |
-
|
| 37 |
-
st.session_state.chat_history = []
|
| 38 |
|
| 39 |
-
|
| 40 |
-
|
|
|
|
|
|
|
| 41 |
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
with chat_container:
|
| 45 |
-
for message in st.session_state.chat_history:
|
| 46 |
-
role, text = message
|
| 47 |
-
if role == "user":
|
| 48 |
-
st.markdown(f"**π§βπ» You:** {text}")
|
| 49 |
else:
|
| 50 |
-
st.
|
| 51 |
-
|
| 52 |
-
# User Input at the bottom
|
| 53 |
-
question = st.text_input("Ask a question:", placeholder="Type your question and press Enter...", key="user_input")
|
| 54 |
-
|
| 55 |
-
if question:
|
| 56 |
-
# Append user question to history
|
| 57 |
-
st.session_state.chat_history.append(("user", question))
|
| 58 |
-
|
| 59 |
-
with st.spinner(""):
|
| 60 |
-
answer = qa_engine.query(question)
|
| 61 |
-
|
| 62 |
-
# Append AI answer to history
|
| 63 |
-
st.session_state.chat_history.append(("ai", answer))
|
| 64 |
|
| 65 |
-
|
| 66 |
-
|
|
|
|
| 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 import QAEngine
|
| 7 |
|
| 8 |
+
st.set_page_config(page_title="AI-Powered Document QA", layout="wide")
|
| 9 |
+
st.title("π AI-Powered Document QA")
|
| 10 |
|
| 11 |
# Initialize processors
|
| 12 |
document_processor = DocumentProcessor()
|
|
|
|
| 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 |
|
|
|
|
| 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
|
| 36 |
+
question = st.text_input("Ask a question from the document:", placeholder="What are the key insights?")
|
|
|
|
| 37 |
|
| 38 |
+
if st.button("π Search & Answer"):
|
| 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")
|