Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -49,7 +49,7 @@ div[data-baseweb="input"]:focus-within {
|
|
49 |
.stButton>button {
|
50 |
background-color: #4CAF50 !important;
|
51 |
color: white !important;
|
52 |
-
border:
|
53 |
border-radius: 8px !important;
|
54 |
padding: 8px 16px;
|
55 |
font-size: 16px;
|
@@ -74,24 +74,25 @@ if not st.session_state.initialized:
|
|
74 |
except Exception as e:
|
75 |
init_message.error(f"Error initializing: {str(e)}")
|
76 |
|
77 |
-
#
|
78 |
-
|
79 |
-
|
80 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
81 |
st.session_state.submit_clicked = True
|
82 |
-
st.session_state.query_answered = True # β
Ensure
|
83 |
-
st.session_state.query_input = "" # β
Clear input
|
84 |
-
st.experimental_rerun() # β
Refresh UI properly
|
85 |
|
86 |
# β
Wrap the text input inside a div for styling
|
87 |
css_class = "answered" if st.session_state.query_answered else ""
|
88 |
st.markdown(f'<div class="{css_class}">', unsafe_allow_html=True)
|
89 |
-
|
90 |
-
# β
Create a form for user input
|
91 |
-
with st.form(key="query_form"):
|
92 |
-
query = st.text_input("Ask your question:", key="query_input", placeholder="Type here...")
|
93 |
-
submit_button = st.form_submit_button("Get Answer", on_click=handle_form_submit)
|
94 |
-
|
95 |
st.markdown("</div>", unsafe_allow_html=True) # β
Close styling div
|
96 |
|
97 |
# β
Display the last question after submission
|
@@ -107,7 +108,7 @@ with col2:
|
|
107 |
word_limit = st.slider("Word limit:", 50, 500, 200)
|
108 |
|
109 |
# β
Process the query if submitted
|
110 |
-
if st.session_state.submit_clicked
|
111 |
st.session_state.submit_clicked = False # Reset flag
|
112 |
|
113 |
with st.spinner("Processing your question..."):
|
@@ -121,9 +122,6 @@ if st.session_state.submit_clicked and st.session_state.last_query:
|
|
121 |
for citation in result["citations"].split("\n"):
|
122 |
st.write(citation)
|
123 |
|
124 |
-
st.session_state.query_answered = True # β
Mark query as answered
|
125 |
-
st.experimental_rerun() # β
Proper rerun to refresh UI
|
126 |
-
|
127 |
except Exception as e:
|
128 |
st.error(f"Error processing query: {str(e)}")
|
129 |
|
|
|
49 |
.stButton>button {
|
50 |
background-color: #4CAF50 !important;
|
51 |
color: white !important;
|
52 |
+
border: 2px solid #4CAF50 !important;
|
53 |
border-radius: 8px !important;
|
54 |
padding: 8px 16px;
|
55 |
font-size: 16px;
|
|
|
74 |
except Exception as e:
|
75 |
init_message.error(f"Error initializing: {str(e)}")
|
76 |
|
77 |
+
# β
Create a form for user input
|
78 |
+
with st.form(key="query_form"):
|
79 |
+
query = st.text_input(
|
80 |
+
"Ask your question:",
|
81 |
+
key="query_input",
|
82 |
+
placeholder="Type here...",
|
83 |
+
)
|
84 |
+
submit_button = st.form_submit_button("Get Answer")
|
85 |
+
|
86 |
+
# β
Handle submission **without st.rerun()**
|
87 |
+
if submit_button:
|
88 |
+
if query.strip():
|
89 |
+
st.session_state.last_query = query.strip()
|
90 |
st.session_state.submit_clicked = True
|
91 |
+
st.session_state.query_answered = True # β
Ensure text box resets to green
|
|
|
|
|
92 |
|
93 |
# β
Wrap the text input inside a div for styling
|
94 |
css_class = "answered" if st.session_state.query_answered else ""
|
95 |
st.markdown(f'<div class="{css_class}">', unsafe_allow_html=True)
|
|
|
|
|
|
|
|
|
|
|
|
|
96 |
st.markdown("</div>", unsafe_allow_html=True) # β
Close styling div
|
97 |
|
98 |
# β
Display the last question after submission
|
|
|
108 |
word_limit = st.slider("Word limit:", 50, 500, 200)
|
109 |
|
110 |
# β
Process the query if submitted
|
111 |
+
if st.session_state.submit_clicked:
|
112 |
st.session_state.submit_clicked = False # Reset flag
|
113 |
|
114 |
with st.spinner("Processing your question..."):
|
|
|
122 |
for citation in result["citations"].split("\n"):
|
123 |
st.write(citation)
|
124 |
|
|
|
|
|
|
|
125 |
except Exception as e:
|
126 |
st.error(f"Error processing query: {str(e)}")
|
127 |
|