Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -4,7 +4,7 @@ import time
|
|
4 |
# FIRST: Set page config before ANY other Streamlit command
|
5 |
st.set_page_config(page_title="Indian Spiritual RAG")
|
6 |
|
7 |
-
# Initialize ALL session state variables
|
8 |
if 'initialized' not in st.session_state:
|
9 |
st.session_state.initialized = False
|
10 |
if 'model' not in st.session_state:
|
@@ -19,6 +19,8 @@ if 'init_time' not in st.session_state:
|
|
19 |
st.session_state.init_time = None
|
20 |
if 'query_answered' not in st.session_state:
|
21 |
st.session_state.query_answered = False # Tracks if the query has been answered
|
|
|
|
|
22 |
|
23 |
# THEN: Import your modules
|
24 |
from rag_engine import process_query, load_model
|
@@ -38,12 +40,6 @@ st.markdown("""
|
|
38 |
margin-bottom: 1rem;
|
39 |
}
|
40 |
|
41 |
-
/* Styling for the submit button */
|
42 |
-
.stButton>button {
|
43 |
-
border: 2px solid #FF5722 !important;
|
44 |
-
border-radius: 8px !important;
|
45 |
-
}
|
46 |
-
|
47 |
/* ✅ Initially green border */
|
48 |
div[data-baseweb="input"] {
|
49 |
border: 2px solid #4CAF50 !important;
|
@@ -60,6 +56,14 @@ div[data-baseweb="input"]:focus-within {
|
|
60 |
div.answered-query {
|
61 |
border: 2px solid #4CAF50 !important;
|
62 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
63 |
</style>
|
64 |
<div class="main-title">Indian Spiritual Texts Q&A</div>
|
65 |
""", unsafe_allow_html=True)
|
@@ -107,21 +111,22 @@ def handle_form_submit():
|
|
107 |
st.session_state.submit_clicked = True
|
108 |
st.session_state.form_submitted = True
|
109 |
st.session_state.query_answered = False # Mark as not yet answered
|
|
|
110 |
|
111 |
# Create a form for handling the user input
|
112 |
with st.form(key="query_form"):
|
113 |
# Apply CSS class dynamically based on submission status
|
114 |
css_class = "answered-query" if st.session_state.query_answered else ""
|
115 |
query = st.text_input(
|
116 |
-
"Ask your question:", key="query_input", value="", placeholder="Type here..."
|
117 |
)
|
118 |
|
119 |
# Submit button within the form
|
120 |
submit_button = st.form_submit_button("Get Answer", on_click=handle_form_submit)
|
121 |
|
122 |
-
#
|
123 |
-
if st.session_state.
|
124 |
-
st.session_state.
|
125 |
st.rerun()
|
126 |
|
127 |
# Display the current question if there is one
|
@@ -153,7 +158,7 @@ if st.session_state.submit_clicked and st.session_state.last_query:
|
|
153 |
for citation in result["citations"].split("\n"):
|
154 |
st.write(citation)
|
155 |
|
156 |
-
# Mark the query as answered
|
157 |
st.session_state.query_answered = True
|
158 |
|
159 |
except Exception as e:
|
|
|
4 |
# FIRST: Set page config before ANY other Streamlit command
|
5 |
st.set_page_config(page_title="Indian Spiritual RAG")
|
6 |
|
7 |
+
# Initialize ALL session state variables
|
8 |
if 'initialized' not in st.session_state:
|
9 |
st.session_state.initialized = False
|
10 |
if 'model' not in st.session_state:
|
|
|
19 |
st.session_state.init_time = None
|
20 |
if 'query_answered' not in st.session_state:
|
21 |
st.session_state.query_answered = False # Tracks if the query has been answered
|
22 |
+
if 'input_cleared' not in st.session_state:
|
23 |
+
st.session_state.input_cleared = False # Ensure input box resets after submission
|
24 |
|
25 |
# THEN: Import your modules
|
26 |
from rag_engine import process_query, load_model
|
|
|
40 |
margin-bottom: 1rem;
|
41 |
}
|
42 |
|
|
|
|
|
|
|
|
|
|
|
|
|
43 |
/* ✅ Initially green border */
|
44 |
div[data-baseweb="input"] {
|
45 |
border: 2px solid #4CAF50 !important;
|
|
|
56 |
div.answered-query {
|
57 |
border: 2px solid #4CAF50 !important;
|
58 |
}
|
59 |
+
|
60 |
+
/* ✅ Green-bordered button */
|
61 |
+
.stButton>button {
|
62 |
+
border: 2px solid #4CAF50 !important;
|
63 |
+
border-radius: 8px !important;
|
64 |
+
color: white !important;
|
65 |
+
background-color: #4CAF50 !important;
|
66 |
+
}
|
67 |
</style>
|
68 |
<div class="main-title">Indian Spiritual Texts Q&A</div>
|
69 |
""", unsafe_allow_html=True)
|
|
|
111 |
st.session_state.submit_clicked = True
|
112 |
st.session_state.form_submitted = True
|
113 |
st.session_state.query_answered = False # Mark as not yet answered
|
114 |
+
st.session_state.input_cleared = True # Flag to clear input
|
115 |
|
116 |
# Create a form for handling the user input
|
117 |
with st.form(key="query_form"):
|
118 |
# Apply CSS class dynamically based on submission status
|
119 |
css_class = "answered-query" if st.session_state.query_answered else ""
|
120 |
query = st.text_input(
|
121 |
+
"Ask your question:", key="query_input", value="", placeholder="Type here..."
|
122 |
)
|
123 |
|
124 |
# Submit button within the form
|
125 |
submit_button = st.form_submit_button("Get Answer", on_click=handle_form_submit)
|
126 |
|
127 |
+
# ✅ Reset input field after submission
|
128 |
+
if st.session_state.input_cleared:
|
129 |
+
st.session_state.input_cleared = False
|
130 |
st.rerun()
|
131 |
|
132 |
# Display the current question if there is one
|
|
|
158 |
for citation in result["citations"].split("\n"):
|
159 |
st.write(citation)
|
160 |
|
161 |
+
# ✅ Mark the query as answered
|
162 |
st.session_state.query_answered = True
|
163 |
|
164 |
except Exception as e:
|