Spaces:
Sleeping
Sleeping
New app.py file with logo in the sidebar
Browse files
app.py
ADDED
|
@@ -0,0 +1,77 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
from rag_query import query_rag
|
| 3 |
+
|
| 4 |
+
# Custom CSS for styling
|
| 5 |
+
st.markdown("""
|
| 6 |
+
<style>
|
| 7 |
+
.main {background-color: #f5f5f5;}
|
| 8 |
+
.stTextInput > div > div > input {border: 2px solid #4CAF50; border-radius: 5px;}
|
| 9 |
+
.stSelectbox > div > div > select {border: 2px solid #4CAF50; border-radius: 5px;}
|
| 10 |
+
.stButton > button {
|
| 11 |
+
background-color: #333333; /* Dark grey */
|
| 12 |
+
color: white;
|
| 13 |
+
border-radius: 5px;
|
| 14 |
+
border: none;
|
| 15 |
+
padding: 10px 20px;
|
| 16 |
+
font-size: 16px;
|
| 17 |
+
}
|
| 18 |
+
.stButton > button:hover {
|
| 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;
|
| 25 |
+
margin-top: 10px; /* Space between logo and text */
|
| 26 |
+
margin-bottom: 20px; /* Space before Instructions */
|
| 27 |
+
}
|
| 28 |
+
.spacer {
|
| 29 |
+
margin-top: 30px; /* Space between text and Instructions */
|
| 30 |
+
}
|
| 31 |
+
</style>
|
| 32 |
+
""", unsafe_allow_html=True)
|
| 33 |
+
|
| 34 |
+
# Initialize session state for password
|
| 35 |
+
if "authenticated" not in st.session_state:
|
| 36 |
+
st.session_state.authenticated = False
|
| 37 |
+
|
| 38 |
+
# Main app title (shown on all screens)
|
| 39 |
+
st.title("United Methodist Church Discipline Assistant")
|
| 40 |
+
st.write("Ask questions about The Book of Discipline 2020-2024!")
|
| 41 |
+
|
| 42 |
+
# Password form (shown only if not authenticated)
|
| 43 |
+
if not st.session_state.authenticated:
|
| 44 |
+
with st.form(key="password_form"):
|
| 45 |
+
password = st.text_input("Enter password:", type="password", key="password")
|
| 46 |
+
submit_password = st.form_submit_button("Login")
|
| 47 |
+
if submit_password:
|
| 48 |
+
if password == "password": # Password as set
|
| 49 |
+
st.session_state.authenticated = True
|
| 50 |
+
st.experimental_rerun() # Refresh to show main app
|
| 51 |
+
else:
|
| 52 |
+
st.error("Incorrect password. Please try again.")
|
| 53 |
+
|
| 54 |
+
# Main app content (shown only if authenticated)
|
| 55 |
+
if st.session_state.authenticated:
|
| 56 |
+
# Interactive input with sample questions
|
| 57 |
+
sample_questions = [
|
| 58 |
+
"Can you tell me the history of United Methodist Church",
|
| 59 |
+
"What does the Constitution say about inclusiveness?",
|
| 60 |
+
"Tell me about John Wesley."
|
| 61 |
+
]
|
| 62 |
+
query = st.selectbox("Pick a question or type your own:", [""] + sample_questions, key="query_select") or st.text_input("Your question:", key="query_input")
|
| 63 |
+
|
| 64 |
+
# Process query and display response
|
| 65 |
+
if st.button("Submit"):
|
| 66 |
+
with st.spinner("Fetching response..."):
|
| 67 |
+
response = query_rag(query)
|
| 68 |
+
st.markdown(response)
|
| 69 |
+
|
| 70 |
+
# Sidebar with logo, text, and instructions (always shown)
|
| 71 |
+
st.sidebar.image("UMC_Logo.png", width=200) # Adjusted logo size for sidebar
|
| 72 |
+
st.sidebar.markdown('<p class="umc-header">United Methodist Communications</p>', unsafe_allow_html=True)
|
| 73 |
+
st.sidebar.markdown('<div class="spacer"></div>', unsafe_allow_html=True) # Add space
|
| 74 |
+
st.sidebar.header("Instructions")
|
| 75 |
+
st.sidebar.write("Enter a question about The United Methodist Church's Book of Discipline. The assistant will retrieve relevant sections and explain them in simple language, citing parts, paragraphs, and titles as needed.")
|
| 76 |
+
st.sidebar.header("About")
|
| 77 |
+
st.sidebar.write("Powered by United Methodist Communications.")
|