Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -19,6 +19,8 @@ if 'init_time' not in st.session_state:
|
|
19 |
st.session_state.init_time = None
|
20 |
if 'form_key' not in st.session_state:
|
21 |
st.session_state.form_key = 0 # This will help us reset the form
|
|
|
|
|
22 |
|
23 |
# THEN: Import your modules
|
24 |
from rag_engine import process_query, load_model
|
@@ -33,7 +35,6 @@ st.markdown("""
|
|
33 |
text-align: center;
|
34 |
margin-bottom: 1rem;
|
35 |
}
|
36 |
-
|
37 |
/* Button styling */
|
38 |
.stButton>button {
|
39 |
background-color: #fff0f0 !important;
|
@@ -46,7 +47,6 @@ st.markdown("""
|
|
46 |
overflow: hidden !important;
|
47 |
text-overflow: ellipsis !important;
|
48 |
}
|
49 |
-
|
50 |
/* Form submit button specific styling */
|
51 |
button[type="submit"],
|
52 |
.stFormSubmit>button,
|
@@ -60,7 +60,6 @@ button[type="submit"],
|
|
60 |
background-color: #fafbff !important;
|
61 |
border-color: #c5cae9 !important;
|
62 |
}
|
63 |
-
|
64 |
/* Input field styling */
|
65 |
div[data-baseweb="input"] {
|
66 |
border: 1px solid #fff0f0 !important;
|
@@ -73,7 +72,6 @@ div[data-baseweb="input"]:focus-within {
|
|
73 |
div[data-baseweb="input"]:active {
|
74 |
border: 1px solid #fff0f0 !important;
|
75 |
}
|
76 |
-
|
77 |
/* Style the st.info boxes */
|
78 |
div.stInfo {
|
79 |
background-color: #f8faff !important;
|
@@ -81,7 +79,6 @@ div.stInfo {
|
|
81 |
border: 1px solid #e1e4f2 !important;
|
82 |
border-radius: 8px !important;
|
83 |
}
|
84 |
-
|
85 |
/* COMBINED SCROLL CONTAINER */
|
86 |
.questions-scroll-container {
|
87 |
width: 100%;
|
@@ -89,12 +86,10 @@ div.stInfo {
|
|
89 |
scrollbar-width: none; /* Firefox */
|
90 |
-ms-overflow-style: none; /* IE and Edge */
|
91 |
}
|
92 |
-
|
93 |
/* Hide scrollbar for Chrome, Safari and Opera */
|
94 |
.questions-scroll-container::-webkit-scrollbar {
|
95 |
display: none;
|
96 |
}
|
97 |
-
|
98 |
/* Inner content that holds both rows */
|
99 |
.questions-content {
|
100 |
display: inline-flex;
|
@@ -103,20 +98,24 @@ div.stInfo {
|
|
103 |
gap: 10px;
|
104 |
padding: 5px 0;
|
105 |
}
|
106 |
-
|
107 |
/* Individual rows */
|
108 |
.questions-row {
|
109 |
display: flex;
|
110 |
flex-direction: row;
|
111 |
gap: 10px;
|
112 |
}
|
113 |
-
|
114 |
/* Placeholder for buttons */
|
115 |
.button-placeholder {
|
116 |
min-height: 38px;
|
117 |
min-width: 120px;
|
118 |
margin: 0 5px;
|
119 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
120 |
</style>
|
121 |
<div class="main-title">Spirituality Q&A</div>
|
122 |
""", unsafe_allow_html=True)
|
@@ -229,20 +228,35 @@ with col1:
|
|
229 |
with col2:
|
230 |
word_limit = st.slider("Word limit:", 50, 500, 200)
|
231 |
|
232 |
-
# Only process the query if explicitly submitted
|
233 |
-
if st.session_state.submit_clicked and st.session_state.last_query:
|
234 |
st.session_state.submit_clicked = False
|
|
|
235 |
|
236 |
with st.spinner("Processing your question..."):
|
237 |
try:
|
|
|
|
|
|
|
|
|
|
|
|
|
238 |
result = process_query(st.session_state.last_query, top_k=top_k, word_limit=word_limit)
|
|
|
|
|
|
|
|
|
|
|
239 |
st.subheader("Answer:")
|
240 |
st.write(result["answer_with_rag"])
|
241 |
st.subheader("Sources:")
|
242 |
for citation in result["citations"].split("\n"):
|
243 |
st.write(citation)
|
|
|
244 |
except Exception as e:
|
245 |
st.error(f"Error processing query: {str(e)}")
|
|
|
|
|
246 |
|
247 |
# Add helpful information
|
248 |
st.markdown("---")
|
|
|
19 |
st.session_state.init_time = None
|
20 |
if 'form_key' not in st.session_state:
|
21 |
st.session_state.form_key = 0 # This will help us reset the form
|
22 |
+
if 'processing' not in st.session_state:
|
23 |
+
st.session_state.processing = False
|
24 |
|
25 |
# THEN: Import your modules
|
26 |
from rag_engine import process_query, load_model
|
|
|
35 |
text-align: center;
|
36 |
margin-bottom: 1rem;
|
37 |
}
|
|
|
38 |
/* Button styling */
|
39 |
.stButton>button {
|
40 |
background-color: #fff0f0 !important;
|
|
|
47 |
overflow: hidden !important;
|
48 |
text-overflow: ellipsis !important;
|
49 |
}
|
|
|
50 |
/* Form submit button specific styling */
|
51 |
button[type="submit"],
|
52 |
.stFormSubmit>button,
|
|
|
60 |
background-color: #fafbff !important;
|
61 |
border-color: #c5cae9 !important;
|
62 |
}
|
|
|
63 |
/* Input field styling */
|
64 |
div[data-baseweb="input"] {
|
65 |
border: 1px solid #fff0f0 !important;
|
|
|
72 |
div[data-baseweb="input"]:active {
|
73 |
border: 1px solid #fff0f0 !important;
|
74 |
}
|
|
|
75 |
/* Style the st.info boxes */
|
76 |
div.stInfo {
|
77 |
background-color: #f8faff !important;
|
|
|
79 |
border: 1px solid #e1e4f2 !important;
|
80 |
border-radius: 8px !important;
|
81 |
}
|
|
|
82 |
/* COMBINED SCROLL CONTAINER */
|
83 |
.questions-scroll-container {
|
84 |
width: 100%;
|
|
|
86 |
scrollbar-width: none; /* Firefox */
|
87 |
-ms-overflow-style: none; /* IE and Edge */
|
88 |
}
|
|
|
89 |
/* Hide scrollbar for Chrome, Safari and Opera */
|
90 |
.questions-scroll-container::-webkit-scrollbar {
|
91 |
display: none;
|
92 |
}
|
|
|
93 |
/* Inner content that holds both rows */
|
94 |
.questions-content {
|
95 |
display: inline-flex;
|
|
|
98 |
gap: 10px;
|
99 |
padding: 5px 0;
|
100 |
}
|
|
|
101 |
/* Individual rows */
|
102 |
.questions-row {
|
103 |
display: flex;
|
104 |
flex-direction: row;
|
105 |
gap: 10px;
|
106 |
}
|
|
|
107 |
/* Placeholder for buttons */
|
108 |
.button-placeholder {
|
109 |
min-height: 38px;
|
110 |
min-width: 120px;
|
111 |
margin: 0 5px;
|
112 |
}
|
113 |
+
/* Hide "Press Enter to submit form" text */
|
114 |
+
.stTextInput label + div + div small,
|
115 |
+
[data-testid="stForm"] small,
|
116 |
+
form small {
|
117 |
+
display: none !important;
|
118 |
+
}
|
119 |
</style>
|
120 |
<div class="main-title">Spirituality Q&A</div>
|
121 |
""", unsafe_allow_html=True)
|
|
|
228 |
with col2:
|
229 |
word_limit = st.slider("Word limit:", 50, 500, 200)
|
230 |
|
231 |
+
# Only process the query if explicitly submitted and not already processing
|
232 |
+
if st.session_state.submit_clicked and st.session_state.last_query and not st.session_state.processing:
|
233 |
st.session_state.submit_clicked = False
|
234 |
+
st.session_state.processing = True
|
235 |
|
236 |
with st.spinner("Processing your question..."):
|
237 |
try:
|
238 |
+
progress_bar = st.progress(0)
|
239 |
+
progress_bar.progress(25, "Generating embeddings...")
|
240 |
+
|
241 |
+
# Call processing function with progress tracking
|
242 |
+
progress_bar.progress(50, "Retrieving relevant passages...")
|
243 |
+
|
244 |
result = process_query(st.session_state.last_query, top_k=top_k, word_limit=word_limit)
|
245 |
+
|
246 |
+
progress_bar.progress(75, "Generating answer...")
|
247 |
+
time.sleep(0.5) # Small delay for visual feedback
|
248 |
+
progress_bar.progress(100)
|
249 |
+
|
250 |
st.subheader("Answer:")
|
251 |
st.write(result["answer_with_rag"])
|
252 |
st.subheader("Sources:")
|
253 |
for citation in result["citations"].split("\n"):
|
254 |
st.write(citation)
|
255 |
+
|
256 |
except Exception as e:
|
257 |
st.error(f"Error processing query: {str(e)}")
|
258 |
+
finally:
|
259 |
+
st.session_state.processing = False
|
260 |
|
261 |
# Add helpful information
|
262 |
st.markdown("---")
|