Spaces:
Sleeping
Sleeping
themanas021
commited on
Update app.py
Browse files
app.py
CHANGED
@@ -60,16 +60,29 @@ if uploaded_file:
|
|
60 |
query = st.text_input("Ask a question:")
|
61 |
|
62 |
if query:
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
60 |
query = st.text_input("Ask a question:")
|
61 |
|
62 |
if query:
|
63 |
+
# Process the query
|
64 |
+
result = qa_chain({"query": query})
|
65 |
+
answer = result["result"]
|
66 |
+
sources = result["source_documents"]
|
67 |
+
|
68 |
+
# Append to conversation history
|
69 |
+
st.session_state.conversation_history.append((query, answer, sources))
|
70 |
+
|
71 |
+
# Display the current answer
|
72 |
+
st.write("**Answer:**", answer)
|
73 |
+
|
74 |
+
# Display the sources
|
75 |
+
st.subheader("Source Documents")
|
76 |
+
for i, doc in enumerate(sources, start=1):
|
77 |
+
st.write(f"**Source {i}:** {doc.metadata.get('source', 'Unknown Source')}")
|
78 |
+
st.write(doc.page_content[:500]) # Display the first 500 characters of the source content
|
79 |
+
|
80 |
+
# Display conversation history
|
81 |
+
st.subheader("Conversation History")
|
82 |
+
for idx, (q, a, s) in enumerate(st.session_state.conversation_history, 1):
|
83 |
+
st.write(f"**Q{idx}:** {q}")
|
84 |
+
st.write(f"**A{idx}:** {a}")
|
85 |
+
st.write(f"**Sources for Q{idx}:**")
|
86 |
+
for i, doc in enumerate(s, start=1):
|
87 |
+
st.write(f"**Source {i}:** {doc.metadata.get('source', 'Unknown Source')}")
|
88 |
+
st.write(doc.page_content[:300]) # Show a snippet for brevity
|