Spaces:
Sleeping
Sleeping
Few enhancements
Browse files
app.py
CHANGED
|
@@ -19,6 +19,18 @@ st.markdown("""
|
|
| 19 |
background-color: #4CAF50; /* Green on hover */
|
| 20 |
color: white;
|
| 21 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 22 |
.umc-header {
|
| 23 |
font-size: 24px; /* Adjusted font size for sidebar */
|
| 24 |
font-weight: bold;
|
|
@@ -42,10 +54,22 @@ if "query_history" not in st.session_state:
|
|
| 42 |
st.session_state.query_history = [] # Store queries and responses
|
| 43 |
if "retrieved_chunks" not in st.session_state:
|
| 44 |
st.session_state.retrieved_chunks = [] # Store retrieved chunks
|
|
|
|
|
|
|
| 45 |
|
| 46 |
# Main app title (shown on all screens)
|
| 47 |
-
st.title("United Methodist Church
|
| 48 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 49 |
|
| 50 |
# Password form (shown only if not authenticated)
|
| 51 |
if not st.session_state.authenticated:
|
|
@@ -66,18 +90,21 @@ if st.session_state.authenticated:
|
|
| 66 |
"Can you tell me the history of United Methodist Church",
|
| 67 |
"What does the Constitution say about inclusiveness?",
|
| 68 |
"Tell me about John Wesley."
|
|
|
|
| 69 |
]
|
| 70 |
query = st.selectbox("Pick a question or type your own:", [""] + sample_questions, key="query_select") or st.text_input("Your question:", key="query_input")
|
| 71 |
|
| 72 |
# Process query and display response
|
| 73 |
if st.button("Submit"):
|
| 74 |
-
with st.spinner("
|
| 75 |
# Retrieve chunks and response
|
| 76 |
results = vector_store.similarity_search(query, k=5) # Assuming vector_store is accessible
|
| 77 |
st.session_state.retrieved_chunks = results # Store retrieved chunks
|
| 78 |
response = query_rag(query)
|
| 79 |
st.session_state.query_history.append((query, response)) # Store query and response
|
| 80 |
-
|
|
|
|
|
|
|
| 81 |
# Display query history
|
| 82 |
for i, (q, r) in enumerate(st.session_state.query_history):
|
| 83 |
st.markdown(f"**Query {i+1}: {q}**")
|
|
@@ -101,18 +128,19 @@ if st.session_state.authenticated:
|
|
| 101 |
|
| 102 |
# New prompt window with sample questions
|
| 103 |
if st.session_state.query_history: # Show only after at least one query
|
| 104 |
-
st.markdown("###
|
| 105 |
selected_query = st.selectbox("Pick another question or type your own:", [""] + sample_questions, key="new_query_select")
|
| 106 |
-
custom_query = st.text_input("
|
| 107 |
# Use custom query if provided, otherwise use selected query
|
| 108 |
new_query = custom_query if custom_query else selected_query
|
| 109 |
if st.button("Submit New Query"):
|
| 110 |
if new_query: # Ensure a query is provided
|
| 111 |
with st.spinner("UMC AI Bot is thinking..."):
|
| 112 |
-
results = vector_store.similarity_search(new_query, k=
|
| 113 |
st.session_state.retrieved_chunks = results
|
| 114 |
response = query_rag(new_query)
|
| 115 |
st.session_state.query_history.append((new_query, response))
|
|
|
|
| 116 |
st.rerun() # Refresh to show new response
|
| 117 |
else:
|
| 118 |
st.warning("Please select a question or enter a new one.")
|
|
|
|
| 19 |
background-color: #4CAF50; /* Green on hover */
|
| 20 |
color: white;
|
| 21 |
}
|
| 22 |
+
.new-chat-button > button {
|
| 23 |
+
background-color: #FF0000; /* Red */
|
| 24 |
+
color: white;
|
| 25 |
+
border-radius: 5px;
|
| 26 |
+
border: none;
|
| 27 |
+
padding: 10px 20px;
|
| 28 |
+
font-size: 16px;
|
| 29 |
+
}
|
| 30 |
+
.new-chat-button > button:hover {
|
| 31 |
+
background-color: #CC0000; /* Darker red on hover */
|
| 32 |
+
color: white;
|
| 33 |
+
}
|
| 34 |
.umc-header {
|
| 35 |
font-size: 24px; /* Adjusted font size for sidebar */
|
| 36 |
font-weight: bold;
|
|
|
|
| 54 |
st.session_state.query_history = [] # Store queries and responses
|
| 55 |
if "retrieved_chunks" not in st.session_state:
|
| 56 |
st.session_state.retrieved_chunks = [] # Store retrieved chunks
|
| 57 |
+
if "new_query_input" not in st.session_state:
|
| 58 |
+
st.session_state.new_query_input = "" # Store new query input
|
| 59 |
|
| 60 |
# Main app title (shown on all screens)
|
| 61 |
+
st.title("United Methodist Church Assistant")
|
| 62 |
+
|
| 63 |
+
# Header with description and New Chat button
|
| 64 |
+
col1, col2 = st.columns([3, 1])
|
| 65 |
+
with col1:
|
| 66 |
+
st.write("Ask questions about The Book of Discipline 2020-2024!")
|
| 67 |
+
with col2:
|
| 68 |
+
if st.button("New Chat", key="new_chat"):
|
| 69 |
+
st.session_state.query_history = []
|
| 70 |
+
st.session_state.retrieved_chunks = []
|
| 71 |
+
st.session_state.new_query_input = ""
|
| 72 |
+
st.rerun()
|
| 73 |
|
| 74 |
# Password form (shown only if not authenticated)
|
| 75 |
if not st.session_state.authenticated:
|
|
|
|
| 90 |
"Can you tell me the history of United Methodist Church",
|
| 91 |
"What does the Constitution say about inclusiveness?",
|
| 92 |
"Tell me about John Wesley."
|
| 93 |
+
" What are special provisions about Sunday prayers"
|
| 94 |
]
|
| 95 |
query = st.selectbox("Pick a question or type your own:", [""] + sample_questions, key="query_select") or st.text_input("Your question:", key="query_input")
|
| 96 |
|
| 97 |
# Process query and display response
|
| 98 |
if st.button("Submit"):
|
| 99 |
+
with st.spinner("UMC AI Bot is thinking..."):
|
| 100 |
# Retrieve chunks and response
|
| 101 |
results = vector_store.similarity_search(query, k=5) # Assuming vector_store is accessible
|
| 102 |
st.session_state.retrieved_chunks = results # Store retrieved chunks
|
| 103 |
response = query_rag(query)
|
| 104 |
st.session_state.query_history.append((query, response)) # Store query and response
|
| 105 |
+
st.session_state.new_query_input = "" # Clear the new query input
|
| 106 |
+
st.rerun() # Refresh to show response
|
| 107 |
+
|
| 108 |
# Display query history
|
| 109 |
for i, (q, r) in enumerate(st.session_state.query_history):
|
| 110 |
st.markdown(f"**Query {i+1}: {q}**")
|
|
|
|
| 128 |
|
| 129 |
# New prompt window with sample questions
|
| 130 |
if st.session_state.query_history: # Show only after at least one query
|
| 131 |
+
st.markdown("### Explore More Insights")
|
| 132 |
selected_query = st.selectbox("Pick another question or type your own:", [""] + sample_questions, key="new_query_select")
|
| 133 |
+
custom_query = st.text_input("What else would you like to know?", value=st.session_state.new_query_input, key=f"new_query_input_{len(st.session_state.query_history)}")
|
| 134 |
# Use custom query if provided, otherwise use selected query
|
| 135 |
new_query = custom_query if custom_query else selected_query
|
| 136 |
if st.button("Submit New Query"):
|
| 137 |
if new_query: # Ensure a query is provided
|
| 138 |
with st.spinner("UMC AI Bot is thinking..."):
|
| 139 |
+
results = vector_store.similarity_search(new_query, k=8)
|
| 140 |
st.session_state.retrieved_chunks = results
|
| 141 |
response = query_rag(new_query)
|
| 142 |
st.session_state.query_history.append((new_query, response))
|
| 143 |
+
st.session_state.new_query_input = "" # Clear the input for the next query
|
| 144 |
st.rerun() # Refresh to show new response
|
| 145 |
else:
|
| 146 |
st.warning("Please select a question or enter a new one.")
|