CoolFace
Apppublic

ajinkya45/SIMPLE-RAG-PDF

sourceHugging Faceupdated 1y agoView on Hugging Face
0likes
app.py30 linesDownload Raw Back to root
1import streamlit as st2from rag_engine import RAGEngine3 4st.set_page_config(page_title="PDF Q&A with RAG")5 6st.title("๐Ÿ” Ask Questions from a PDF")7 8rag = RAGEngine()9 10uploaded_file = st.file_uploader("Upload a PDF", type=["pdf"])11 12if uploaded_file is not None:13    with st.spinner("Reading PDF and indexing..."):14        rag.load_from_pdf(uploaded_file)15        st.success("PDF processed and ready!")16 17    user_query = st.text_input("Ask a question based on the uploaded PDF:")18 19    if user_query:20        with st.spinner("Thinking..."):21            top_k=322            23            context = rag.retrieve(user_query, top_k=top_k)24            st.subheader("๐Ÿ“„ Retrieved Context")25            st.write(context)26 27            answer = rag.generate_answer(user_query, top_k=top_k)28            st.subheader("๐Ÿ’ก Answer")29            st.write(answer)30