Spaces:
Sleeping
Sleeping
File size: 1,163 Bytes
a6d6e36 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
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}") |