Spaces:
Sleeping
Sleeping
Update app,py
Browse files
app.py
CHANGED
@@ -19,8 +19,6 @@ 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 |
-
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
|
@@ -41,28 +39,28 @@ st.markdown("""
|
|
41 |
}
|
42 |
|
43 |
/* β
Initially green border */
|
44 |
-
|
45 |
border: 2px solid #4CAF50 !important;
|
46 |
border-radius: 8px !important;
|
47 |
transition: border 0.3s ease-in-out;
|
48 |
}
|
49 |
|
50 |
/* π΄ Change to red while typing */
|
51 |
-
|
52 |
border: 2px solid #FF5722 !important;
|
53 |
}
|
54 |
|
55 |
/* β
Revert to green after submission */
|
56 |
-
|
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:
|
65 |
-
background-color:
|
66 |
}
|
67 |
</style>
|
68 |
<div class="main-title">Indian Spiritual Texts Q&A</div>
|
@@ -100,37 +98,29 @@ elif st.session_state.init_time is not None:
|
|
100 |
init_message.empty()
|
101 |
st.session_state.init_time = None # Reset timer after clearing
|
102 |
|
103 |
-
# Handle form submission - ensures input is cleared and focus is removed
|
104 |
-
if 'form_submitted' not in st.session_state:
|
105 |
-
st.session_state.form_submitted = False
|
106 |
-
|
107 |
# Function to handle form submission
|
108 |
def handle_form_submit():
|
109 |
if st.session_state.query_input:
|
110 |
st.session_state.last_query = st.session_state.query_input
|
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.
|
115 |
|
116 |
-
# Create a form for handling
|
117 |
with st.form(key="query_form"):
|
118 |
-
#
|
119 |
-
css_class = "answered-query" if st.session_state.query_answered else ""
|
120 |
query = st.text_input(
|
121 |
-
"Ask your question:",
|
|
|
|
|
|
|
122 |
)
|
123 |
|
124 |
-
# Submit button
|
125 |
submit_button = st.form_submit_button("Get Answer", on_click=handle_form_submit)
|
126 |
|
127 |
-
# β
|
128 |
-
if st.session_state.
|
129 |
-
st.session_state.input_cleared = False
|
130 |
-
st.rerun()
|
131 |
-
|
132 |
-
# Display the current question if there is one
|
133 |
-
if st.session_state.last_query:
|
134 |
st.markdown("### Current Question:")
|
135 |
st.info(st.session_state.last_query)
|
136 |
|
@@ -141,12 +131,10 @@ with col1:
|
|
141 |
with col2:
|
142 |
word_limit = st.slider("Word limit:", 50, 500, 200)
|
143 |
|
144 |
-
#
|
145 |
if st.session_state.submit_clicked and st.session_state.last_query:
|
146 |
-
# Reset
|
147 |
-
st.session_state.submit_clicked = False
|
148 |
|
149 |
-
# Process the query
|
150 |
with st.spinner("Processing your question..."):
|
151 |
try:
|
152 |
result = process_query(st.session_state.last_query, top_k=top_k, word_limit=word_limit)
|
@@ -158,8 +146,7 @@ if st.session_state.submit_clicked and st.session_state.last_query:
|
|
158 |
for citation in result["citations"].split("\n"):
|
159 |
st.write(citation)
|
160 |
|
161 |
-
# β
Mark
|
162 |
-
st.session_state.query_answered = True
|
163 |
|
164 |
except Exception as e:
|
165 |
st.error(f"Error processing query: {str(e)}")
|
|
|
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
|
|
|
39 |
}
|
40 |
|
41 |
/* β
Initially green border */
|
42 |
+
input[type="text"] {
|
43 |
border: 2px solid #4CAF50 !important;
|
44 |
border-radius: 8px !important;
|
45 |
transition: border 0.3s ease-in-out;
|
46 |
}
|
47 |
|
48 |
/* π΄ Change to red while typing */
|
49 |
+
input[type="text"]:focus {
|
50 |
border: 2px solid #FF5722 !important;
|
51 |
}
|
52 |
|
53 |
/* β
Revert to green after submission */
|
54 |
+
.answered-query input[type="text"] {
|
55 |
border: 2px solid #4CAF50 !important;
|
56 |
}
|
57 |
|
58 |
+
/* β
Green-bordered button (not filled) */
|
59 |
.stButton>button {
|
60 |
border: 2px solid #4CAF50 !important;
|
61 |
border-radius: 8px !important;
|
62 |
+
color: black !important;
|
63 |
+
background-color: white !important;
|
64 |
}
|
65 |
</style>
|
66 |
<div class="main-title">Indian Spiritual Texts Q&A</div>
|
|
|
98 |
init_message.empty()
|
99 |
st.session_state.init_time = None # Reset timer after clearing
|
100 |
|
|
|
|
|
|
|
|
|
101 |
# Function to handle form submission
|
102 |
def handle_form_submit():
|
103 |
if st.session_state.query_input:
|
104 |
st.session_state.last_query = st.session_state.query_input
|
105 |
st.session_state.submit_clicked = True
|
|
|
106 |
st.session_state.query_answered = False # Mark as not yet answered
|
107 |
+
st.session_state.query_input = "" # Clear input box after submission
|
108 |
|
109 |
+
# β
Create a form for handling user input
|
110 |
with st.form(key="query_form"):
|
111 |
+
# Input field with dynamic border behavior
|
|
|
112 |
query = st.text_input(
|
113 |
+
"Ask your question:",
|
114 |
+
key="query_input",
|
115 |
+
value="",
|
116 |
+
placeholder="Type here..."
|
117 |
)
|
118 |
|
119 |
+
# Submit button
|
120 |
submit_button = st.form_submit_button("Get Answer", on_click=handle_form_submit)
|
121 |
|
122 |
+
# β
Display the last question after submission
|
123 |
+
if st.session_state.submit_clicked and st.session_state.last_query:
|
|
|
|
|
|
|
|
|
|
|
124 |
st.markdown("### Current Question:")
|
125 |
st.info(st.session_state.last_query)
|
126 |
|
|
|
131 |
with col2:
|
132 |
word_limit = st.slider("Word limit:", 50, 500, 200)
|
133 |
|
134 |
+
# β
Process the query if submitted
|
135 |
if st.session_state.submit_clicked and st.session_state.last_query:
|
136 |
+
st.session_state.submit_clicked = False # Reset flag
|
|
|
137 |
|
|
|
138 |
with st.spinner("Processing your question..."):
|
139 |
try:
|
140 |
result = process_query(st.session_state.last_query, top_k=top_k, word_limit=word_limit)
|
|
|
146 |
for citation in result["citations"].split("\n"):
|
147 |
st.write(citation)
|
148 |
|
149 |
+
st.session_state.query_answered = True # β
Mark query as answered
|
|
|
150 |
|
151 |
except Exception as e:
|
152 |
st.error(f"Error processing query: {str(e)}")
|