Update app.py
Browse files
app.py
CHANGED
@@ -88,6 +88,10 @@ def load_custom_css():
|
|
88 |
</style>
|
89 |
""", unsafe_allow_html=True)
|
90 |
|
|
|
|
|
|
|
|
|
91 |
def initialize_pipeline():
|
92 |
"""Initialize RAG pipeline with configurations"""
|
93 |
try:
|
@@ -274,17 +278,16 @@ def main():
|
|
274 |
</label>
|
275 |
""", unsafe_allow_html=True)
|
276 |
|
277 |
-
#
|
278 |
if "query_input" not in st.session_state:
|
279 |
st.session_state.query_input = ""
|
280 |
|
281 |
query = st.text_input(
|
282 |
"",
|
283 |
placeholder="เช่น: วันสุดท้ายของการสอบปากเปล่าในภาคเรียนที่ 1/2567 คือวันที่เท่าไร?",
|
284 |
-
key="query_input"
|
285 |
)
|
286 |
-
|
287 |
-
# Button layout inside main() function
|
288 |
col1, col2, col3 = st.columns([1, 1, 4])
|
289 |
|
290 |
with col1:
|
@@ -313,8 +316,10 @@ def main():
|
|
313 |
with st.spinner("🔍 กำลังค้นหาคำตอบ..."):
|
314 |
result = st.session_state.pipeline.process_query(query)
|
315 |
add_to_history("assistant", result["answer"])
|
316 |
-
|
317 |
-
|
|
|
|
|
318 |
with st.expander("📚 แสดงข้อมูลอ้างอิง", expanded=False):
|
319 |
for i, doc in enumerate(result["documents"], 1):
|
320 |
st.markdown(f"""
|
@@ -323,14 +328,13 @@ def main():
|
|
323 |
{doc.content}
|
324 |
</div>
|
325 |
""", unsafe_allow_html=True)
|
326 |
-
|
327 |
with st.expander("🔍 รายละเอียดการวิเคราะห์คำถาม", expanded=False):
|
328 |
st.json(result["query_info"])
|
329 |
-
|
330 |
st.rerun()
|
331 |
except Exception as e:
|
332 |
st.error(f"❌ เกิดข้อผิดพลาด: {str(e)}")
|
333 |
-
|
334 |
elif send_query and not query:
|
335 |
st.warning("⚠️ กรุณาระบุคำถาม")
|
336 |
|
|
|
88 |
</style>
|
89 |
""", unsafe_allow_html=True)
|
90 |
|
91 |
+
# Define a callback to reset query_input
|
92 |
+
def reset_query_input():
|
93 |
+
st.session_state.query_input = ""
|
94 |
+
|
95 |
def initialize_pipeline():
|
96 |
"""Initialize RAG pipeline with configurations"""
|
97 |
try:
|
|
|
278 |
</label>
|
279 |
""", unsafe_allow_html=True)
|
280 |
|
281 |
+
# Inside the main function
|
282 |
if "query_input" not in st.session_state:
|
283 |
st.session_state.query_input = ""
|
284 |
|
285 |
query = st.text_input(
|
286 |
"",
|
287 |
placeholder="เช่น: วันสุดท้ายของการสอบปากเปล่าในภาคเรียนที่ 1/2567 คือวันที่เท่าไร?",
|
288 |
+
key="query_input",
|
289 |
)
|
290 |
+
|
|
|
291 |
col1, col2, col3 = st.columns([1, 1, 4])
|
292 |
|
293 |
with col1:
|
|
|
316 |
with st.spinner("🔍 กำลังค้นหาคำตอบ..."):
|
317 |
result = st.session_state.pipeline.process_query(query)
|
318 |
add_to_history("assistant", result["answer"])
|
319 |
+
|
320 |
+
# Reset the query input
|
321 |
+
reset_query_input()
|
322 |
+
|
323 |
with st.expander("📚 แสดงข้อมูลอ้างอิง", expanded=False):
|
324 |
for i, doc in enumerate(result["documents"], 1):
|
325 |
st.markdown(f"""
|
|
|
328 |
{doc.content}
|
329 |
</div>
|
330 |
""", unsafe_allow_html=True)
|
331 |
+
|
332 |
with st.expander("🔍 รายละเอียดการวิเคราะห์คำถาม", expanded=False):
|
333 |
st.json(result["query_info"])
|
334 |
+
|
335 |
st.rerun()
|
336 |
except Exception as e:
|
337 |
st.error(f"❌ เกิดข้อผิดพลาด: {str(e)}")
|
|
|
338 |
elif send_query and not query:
|
339 |
st.warning("⚠️ กรุณาระบุคำถาม")
|
340 |
|