Update app.py
Browse files
app.py
CHANGED
@@ -2,6 +2,7 @@ import streamlit as st
|
|
2 |
import json
|
3 |
import os
|
4 |
from datetime import datetime, timedelta
|
|
|
5 |
from huggingface_hub import HfApi
|
6 |
from pathlib import Path
|
7 |
from calendar_rag import (
|
@@ -120,11 +121,9 @@ def load_qa_history():
|
|
120 |
st.error(f"Error loading QA history: {str(e)}")
|
121 |
return []
|
122 |
|
123 |
-
|
124 |
def save_qa_history(history_entry):
|
125 |
"""Save QA history entry to local JSON file and push to Hugging Face"""
|
126 |
try:
|
127 |
-
|
128 |
history_file = Path("qa_history.json")
|
129 |
|
130 |
# Initialize or load existing history
|
@@ -270,7 +269,7 @@ def main():
|
|
270 |
key="query_input"
|
271 |
)
|
272 |
|
273 |
-
# Button layout
|
274 |
col1, col2, col3 = st.columns([1, 1, 4])
|
275 |
|
276 |
with col1:
|
@@ -288,13 +287,12 @@ def main():
|
|
288 |
use_container_width=True,
|
289 |
key="clear_history_button"
|
290 |
)
|
291 |
-
|
292 |
# Process query
|
293 |
if send_query and query:
|
294 |
if st.session_state.pipeline is None:
|
295 |
st.error("❌ ไม่สามารถเชื่อมต่อกับระบบได้ กรุณาลองใหม่อีกครั้ง")
|
296 |
return
|
297 |
-
|
298 |
add_to_history("user", query)
|
299 |
|
300 |
try:
|
@@ -314,17 +312,19 @@ def main():
|
|
314 |
with st.expander("🔍 รายละเอียดการวิเคราะห์คำถาม", expanded=False):
|
315 |
st.json(result["query_info"])
|
316 |
|
|
|
|
|
317 |
except Exception as e:
|
318 |
st.error(f"❌ เกิดข้อผิดพลาด: {str(e)}")
|
319 |
|
320 |
elif send_query and not query:
|
321 |
st.warning("⚠️ กรุณาระบุคำถาม")
|
322 |
-
|
323 |
-
|
324 |
-
|
325 |
-
|
326 |
-
|
327 |
-
|
328 |
|
329 |
with info_col:
|
330 |
# System information
|
@@ -366,11 +366,5 @@ def main():
|
|
366 |
"พร้อมใช้งาน" if st.session_state.pipeline else "ไม่พร้อมใช้งาน"
|
367 |
), unsafe_allow_html=True)
|
368 |
|
369 |
-
# Handle clear history action
|
370 |
-
if clear_history:
|
371 |
-
st.session_state.chat_history = []
|
372 |
-
clear_qa_history()
|
373 |
-
st.rerun()
|
374 |
-
|
375 |
if __name__ == "__main__":
|
376 |
main()
|
|
|
2 |
import json
|
3 |
import os
|
4 |
from datetime import datetime, timedelta
|
5 |
+
import subprocess
|
6 |
from huggingface_hub import HfApi
|
7 |
from pathlib import Path
|
8 |
from calendar_rag import (
|
|
|
121 |
st.error(f"Error loading QA history: {str(e)}")
|
122 |
return []
|
123 |
|
|
|
124 |
def save_qa_history(history_entry):
|
125 |
"""Save QA history entry to local JSON file and push to Hugging Face"""
|
126 |
try:
|
|
|
127 |
history_file = Path("qa_history.json")
|
128 |
|
129 |
# Initialize or load existing history
|
|
|
269 |
key="query_input"
|
270 |
)
|
271 |
|
272 |
+
# Button layout inside main() function
|
273 |
col1, col2, col3 = st.columns([1, 1, 4])
|
274 |
|
275 |
with col1:
|
|
|
287 |
use_container_width=True,
|
288 |
key="clear_history_button"
|
289 |
)
|
|
|
290 |
# Process query
|
291 |
if send_query and query:
|
292 |
if st.session_state.pipeline is None:
|
293 |
st.error("❌ ไม่สามารถเชื่อมต่อกับระบบได้ กรุณาลองใหม่อีกครั้ง")
|
294 |
return
|
295 |
+
|
296 |
add_to_history("user", query)
|
297 |
|
298 |
try:
|
|
|
312 |
with st.expander("🔍 รายละเอียดการวิเคราะห์คำถาม", expanded=False):
|
313 |
st.json(result["query_info"])
|
314 |
|
315 |
+
st.rerun()
|
316 |
+
|
317 |
except Exception as e:
|
318 |
st.error(f"❌ เกิดข้อผิดพลาด: {str(e)}")
|
319 |
|
320 |
elif send_query and not query:
|
321 |
st.warning("⚠️ กรุณาระบุคำถาม")
|
322 |
+
|
323 |
+
# Handle clear history action
|
324 |
+
if clear_history:
|
325 |
+
st.session_state.chat_history = []
|
326 |
+
clear_qa_history()
|
327 |
+
st.rerun()
|
328 |
|
329 |
with info_col:
|
330 |
# System information
|
|
|
366 |
"พร้อมใช้งาน" if st.session_state.pipeline else "ไม่พร้อมใช้งาน"
|
367 |
), unsafe_allow_html=True)
|
368 |
|
|
|
|
|
|
|
|
|
|
|
|
|
369 |
if __name__ == "__main__":
|
370 |
main()
|