docling_rag / app.py
NEXAS's picture
Update app.py
b1b6964 verified
raw
history blame
1.61 kB
import streamlit as st
import os
import json
from utils.ingestion import DocumentProcessor
from utils.llm import LLMProcessor
from utils.qa_engine import QAEngine
# Set up Streamlit page
st.set_page_config(page_title="AI-Powered Document QA", layout="wide")
st.title("πŸ“„ AI-Powered Document QA")
# Initialize processors
document_processor = DocumentProcessor()
llm_processor = LLMProcessor()
qa_engine = QAEngine()
# File uploader
st.sidebar.header("Upload a PDF")
uploaded_file = st.sidebar.file_uploader("Choose a PDF file", type=["pdf"])
if uploaded_file:
# Save file to a temporary path
pdf_path = f"temp/{uploaded_file.name}"
os.makedirs("temp", exist_ok=True)
with open(pdf_path, "wb") as f:
f.write(uploaded_file.read())
st.sidebar.success("βœ… File uploaded successfully!")
# Process the document
with st.spinner("πŸ”„ Processing document..."):
document_processor.process_document(pdf_path)
st.sidebar.success("βœ… Document processed successfully!")
# Query input
question = st.text_input("Ask a question from the document:", placeholder="What are the key insights?")
if st.button("πŸ” Search & Answer"):
if question:
with st.spinner("🧠 Searching for relevant context..."):
answer = qa_engine.query(question)
st.subheader("πŸ“ Answer:")
st.write(answer)
else:
st.warning("⚠️ Please enter a question.")
# Footer
st.markdown("---")
st.caption("πŸ€– Powered by ChromaDB + Groq LLM | Built with ❀️ using Streamlit")