Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -17,6 +17,10 @@ if 'submit_clicked' not in st.session_state:
|
|
17 |
st.session_state.submit_clicked = False
|
18 |
if 'init_time' not in st.session_state:
|
19 |
st.session_state.init_time = None
|
|
|
|
|
|
|
|
|
20 |
|
21 |
# THEN: Import your modules
|
22 |
from rag_engine import process_query, load_model
|
@@ -68,7 +72,7 @@ if not st.session_state.initialized:
|
|
68 |
st.session_state.init_time = time.time()
|
69 |
init_message.success("System initialized successfully!")
|
70 |
time.sleep(0.1)
|
71 |
-
st.
|
72 |
except Exception as e:
|
73 |
init_message.error(f"Error initializing: {str(e)}")
|
74 |
|
@@ -78,19 +82,29 @@ elif st.session_state.init_time is not None:
|
|
78 |
init_message.empty()
|
79 |
st.session_state.init_time = None
|
80 |
|
|
|
|
|
|
|
|
|
|
|
81 |
# Handle form submission
|
82 |
def handle_form_submit():
|
83 |
if st.session_state.query_input:
|
84 |
st.session_state.last_query = st.session_state.query_input
|
85 |
st.session_state.submit_clicked = True
|
86 |
st.session_state.query_input = ""
|
87 |
-
st.
|
88 |
|
89 |
# Create a form for handling the user input
|
90 |
with st.form(key="query_form"):
|
91 |
query = st.text_input("Ask your question:", key="query_input", placeholder="Press enter to submit question")
|
92 |
submit_button = st.form_submit_button("Get Answer", on_click=handle_form_submit)
|
93 |
|
|
|
|
|
|
|
|
|
|
|
94 |
# Display the current question if there is one
|
95 |
if st.session_state.last_query:
|
96 |
st.markdown("### Current Question:")
|
|
|
17 |
st.session_state.submit_clicked = False
|
18 |
if 'init_time' not in st.session_state:
|
19 |
st.session_state.init_time = None
|
20 |
+
if 'form_needs_rerun' not in st.session_state:
|
21 |
+
st.session_state.form_needs_rerun = False
|
22 |
+
if 'init_needs_rerun' not in st.session_state:
|
23 |
+
st.session_state.init_needs_rerun = False
|
24 |
|
25 |
# THEN: Import your modules
|
26 |
from rag_engine import process_query, load_model
|
|
|
72 |
st.session_state.init_time = time.time()
|
73 |
init_message.success("System initialized successfully!")
|
74 |
time.sleep(0.1)
|
75 |
+
st.session_state.init_needs_rerun = True
|
76 |
except Exception as e:
|
77 |
init_message.error(f"Error initializing: {str(e)}")
|
78 |
|
|
|
82 |
init_message.empty()
|
83 |
st.session_state.init_time = None
|
84 |
|
85 |
+
# Handle rerun for initialization
|
86 |
+
if st.session_state.init_needs_rerun:
|
87 |
+
st.session_state.init_needs_rerun = False
|
88 |
+
st.rerun()
|
89 |
+
|
90 |
# Handle form submission
|
91 |
def handle_form_submit():
|
92 |
if st.session_state.query_input:
|
93 |
st.session_state.last_query = st.session_state.query_input
|
94 |
st.session_state.submit_clicked = True
|
95 |
st.session_state.query_input = ""
|
96 |
+
st.session_state.form_needs_rerun = True
|
97 |
|
98 |
# Create a form for handling the user input
|
99 |
with st.form(key="query_form"):
|
100 |
query = st.text_input("Ask your question:", key="query_input", placeholder="Press enter to submit question")
|
101 |
submit_button = st.form_submit_button("Get Answer", on_click=handle_form_submit)
|
102 |
|
103 |
+
# Handle rerun for form submission
|
104 |
+
if st.session_state.form_needs_rerun:
|
105 |
+
st.session_state.form_needs_rerun = False
|
106 |
+
st.rerun()
|
107 |
+
|
108 |
# Display the current question if there is one
|
109 |
if st.session_state.last_query:
|
110 |
st.markdown("### Current Question:")
|