ankanghosh commited on
Commit
668b17d
Β·
verified Β·
1 Parent(s): 9ac9057

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +16 -18
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: none !important;
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
- # Function to handle form submission
78
- def handle_form_submit():
79
- if st.session_state.query_input:
80
- st.session_state.last_query = st.session_state.query_input
 
 
 
 
 
 
 
 
 
81
  st.session_state.submit_clicked = True
82
- st.session_state.query_answered = True # βœ… Ensure it resets to green
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 and st.session_state.last_query:
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