Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -1,10 +1,7 @@
|
|
1 |
import os
|
2 |
-
|
3 |
import streamlit as st
|
4 |
-
|
5 |
from rag_utility import process_document_to_chromadb, answer_question
|
6 |
|
7 |
-
|
8 |
# Set working directory (optional, ensures saving in project dir)
|
9 |
working_dir = os.getcwd()
|
10 |
|
@@ -13,44 +10,51 @@ st.title("π DeepSeek-R1 vs π¦ Llama-3")
|
|
13 |
# File uploader
|
14 |
uploaded_file = st.file_uploader("Upload a PDF file", type=["pdf"])
|
15 |
|
16 |
-
|
17 |
-
|
18 |
-
save_path = os.path.join(working_dir, uploaded_file.name)
|
19 |
-
# Save file
|
20 |
-
with open(save_path, "wb") as f:
|
21 |
-
f.write(uploaded_file.getbuffer())
|
22 |
-
|
23 |
-
process_documents = process_document_to_chromadb(uploaded_file.name)
|
24 |
-
st.info("Document Processed Successfully")
|
25 |
-
|
26 |
|
27 |
user_question = st.text_area("Ask your question from the document")
|
28 |
|
29 |
if st.button("Answer"):
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
st.
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
import os
|
|
|
2 |
import streamlit as st
|
|
|
3 |
from rag_utility import process_document_to_chromadb, answer_question
|
4 |
|
|
|
5 |
# Set working directory (optional, ensures saving in project dir)
|
6 |
working_dir = os.getcwd()
|
7 |
|
|
|
10 |
# File uploader
|
11 |
uploaded_file = st.file_uploader("Upload a PDF file", type=["pdf"])
|
12 |
|
13 |
+
# Checkbox flag to track processing status
|
14 |
+
doc_processed = False
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
15 |
|
16 |
user_question = st.text_area("Ask your question from the document")
|
17 |
|
18 |
if st.button("Answer"):
|
19 |
+
if uploaded_file is None:
|
20 |
+
st.error("Please upload a PDF file before asking a question.")
|
21 |
+
else:
|
22 |
+
# Process the document only when answering the first time
|
23 |
+
if not doc_processed:
|
24 |
+
save_path = os.path.join(working_dir, uploaded_file.name)
|
25 |
+
with open(save_path, "wb") as f:
|
26 |
+
f.write(uploaded_file.getbuffer())
|
27 |
+
|
28 |
+
process_document_to_chromadb(uploaded_file.name)
|
29 |
+
doc_processed = True # Mark as processed
|
30 |
+
st.info("Document Processed Successfully")
|
31 |
+
|
32 |
+
# Get answers
|
33 |
+
answer = answer_question(user_question)
|
34 |
+
answer_deepseek = answer["answer_deepseek"]
|
35 |
+
answer_llama3 = answer["answer_llama3"]
|
36 |
+
|
37 |
+
# Display side-by-side answers
|
38 |
+
col1, col2 = st.columns(2)
|
39 |
+
|
40 |
+
with col1:
|
41 |
+
st.markdown("### DeepSeek-r1 Response")
|
42 |
+
st.markdown(
|
43 |
+
f"""
|
44 |
+
<div style="border: 1px solid #ccc; padding: 10px; border-radius: 5px; background-color: #f9f9f9; padding: 10px;">
|
45 |
+
{answer_deepseek}
|
46 |
+
</div>
|
47 |
+
""",
|
48 |
+
unsafe_allow_html=True
|
49 |
+
)
|
50 |
+
|
51 |
+
with col2:
|
52 |
+
st.markdown("### Llama-3 Response")
|
53 |
+
st.markdown(
|
54 |
+
f"""
|
55 |
+
<div style="border: 1px solid #ccc; padding: 10px; border-radius: 5px; background-color: #f9f9f9; padding: 10px;">
|
56 |
+
{answer_llama3}
|
57 |
+
</div>
|
58 |
+
""",
|
59 |
+
unsafe_allow_html=True
|
60 |
+
)
|