themanas021 commited on
Commit
ac69353
·
verified ·
1 Parent(s): 880d9dc

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +26 -13
app.py CHANGED
@@ -60,16 +60,29 @@ if uploaded_file:
60
  query = st.text_input("Ask a question:")
61
 
62
  if query:
63
- result = qa_chain({"query": query})
64
- answer = result["result"]
65
- st.session_state.conversation_history.append((query, answer))
66
-
67
- # Display the current answer
68
- st.write("**Answer:**", answer)
69
-
70
- # Display conversation history
71
- st.subheader("Conversation History")
72
- for idx, (q, a) in enumerate(st.session_state.conversation_history, 1):
73
- st.write(f"**Q{idx}:** {q}")
74
- st.write(f"**A{idx}:** {a}")
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