|
import os |
|
import streamlit as st |
|
from rag_utility import process_document_to_chroma_db, answer_question |
|
|
|
|
|
working_dir = r"pdfs" |
|
|
|
|
|
os.makedirs(working_dir, exist_ok=True) |
|
|
|
st.title("π DeepSeek-R1 - Document RAG") |
|
|
|
|
|
uploaded_file = st.file_uploader("π Upload a PDF file", type=["pdf"]) |
|
|
|
if uploaded_file is not None: |
|
|
|
save_path = os.path.join(working_dir, uploaded_file.name) |
|
|
|
|
|
try: |
|
with open(save_path, "wb") as f: |
|
f.write(uploaded_file.getbuffer()) |
|
|
|
st.success(f"β
File '{uploaded_file.name}' uploaded successfully!") |
|
|
|
|
|
progress = st.progress(0) |
|
|
|
try: |
|
st.info("π Processing document... Please wait.") |
|
progress.progress(50) |
|
process_document_to_chroma_db(working_dir) |
|
progress.progress(100) |
|
st.success("β
Document processed successfully! Ready for Q&A.") |
|
except Exception as e: |
|
progress.progress(0) |
|
st.error(f"β οΈ Error processing document: {e}") |
|
|
|
except Exception as e: |
|
st.error(f"β οΈ Error saving file: {e}") |
|
|
|
|
|
user_question = st.text_area("π¬ Ask your question about the document") |
|
|
|
if st.button("π Get Answer"): |
|
if user_question.strip(): |
|
try: |
|
answer = answer_question(user_question) |
|
st.markdown("### π€ DeepSeek-R1 Response:") |
|
st.markdown(f"**{answer}**") |
|
except Exception as e: |
|
st.error(f"β οΈ Error generating answer: {e}") |
|
else: |
|
st.warning("β οΈ Please enter a question before clicking 'Get Answer'.") |
|
|