Spaces:
Sleeping
Sleeping
import streamlit as st | |
from document_chat import ingest_pdf, process_query_with_memory | |
#configure streamlit app | |
st.set_page_config(page_title="AI Document Q&A Chatbot", layout="wide") | |
st.title("π AI-Powered Document Chatbot") | |
st.write("Upload a document and ask questions!") | |
#upload document | |
uploaded_file = st.file_uploader("Upload a PDF", type=["pdf"]) | |
if uploaded_file: | |
file_path = "uploaded_doc.pdf" | |
with open(file_path, "wb") as f: | |
f.write(uploaded_file.getbuffer()) | |
st.success("File uploaded! Processing...") | |
ingest_pdf(file_path) | |
if "chat_history" not in st.session_state: | |
st.session_state["chat_history"] = [] | |
query = st.text_input("Ask a question:") | |
if query: | |
with st.spinner("Thinking..."): | |
response = process_query_with_memory(query, st.session_state["chat_history"]) | |
st.session_state["chat_history"].append((query, response)) | |
st.write(response) | |
# Show chat history | |
if st.session_state["chat_history"]: | |
st.subheader("Chat History") | |
for q, a in st.session_state["chat_history"]: | |
st.write(f"**User:** {q}") | |
st.write(f"**Bot:** {a}") |