Ines1994 commited on
Commit
ef83a22
·
verified ·
1 Parent(s): d808d33

Upload app.py

Browse files
Files changed (1) hide show
  1. app.py +17 -9
app.py CHANGED
@@ -163,6 +163,19 @@ def main():
163
  with st.chat_message(msg["role"]):
164
  st.markdown(msg["content"])
165
 
 
 
 
 
 
 
 
 
 
 
 
 
 
166
  # Input
167
  is_ar = st.session_state.get("lang", "ar") == "ar"
168
  placeholder = "اسأل عن المناظرات، الشروط، أو إجراءات التكوين..." if is_ar else "Posez des questions sur les concours, conditions ou procédures..."
@@ -206,18 +219,13 @@ def main():
206
 
207
  st.markdown(full_response)
208
 
209
- # ══ اقتراحات ذكية بعد الإجابة (مثل Claude/ChatGPT) ══
210
  if tool_used not in ("chat", "ask_user_profile") and not result.get("needs_user_input"):
211
  with st.spinner("💡 ..."):
212
  suggestions = agent.generate_suggestions(final_q, full_response, lang)
213
- if suggestions:
214
- sug_label = "💡 قد يهمك أيضاً:" if lang == "ar" else "💡 Vous pourriez aussi demander:"
215
- st.markdown(f"---\n**{sug_label}**")
216
- sug_cols = st.columns(len(suggestions))
217
- for i, sug in enumerate(suggestions):
218
- if sug_cols[i].button(sug, key=f"sug_{len(st.session_state.chat_messages)}_{i}"):
219
- st.session_state.pending_q = sug
220
- st.rerun()
221
 
222
  st.session_state.chat_messages.append({"role": "assistant", "content": full_response})
223
  st.session_state.last_tool = tool_used
 
163
  with st.chat_message(msg["role"]):
164
  st.markdown(msg["content"])
165
 
166
+ # ══ عرض الاقتراحات بعد آخر إجابة ══
167
+ suggestions = st.session_state.get("last_suggestions", [])
168
+ if suggestions and st.session_state.chat_messages:
169
+ lang = st.session_state.get("lang", "ar")
170
+ sug_label = "💡 قد يهمك أيضاً:" if lang == "ar" else "💡 Vous pourriez aussi demander:"
171
+ st.markdown(f"---\n**{sug_label}**")
172
+ sug_cols = st.columns(len(suggestions))
173
+ for i, sug in enumerate(suggestions):
174
+ if sug_cols[i].button(sug, key=f"sug_{len(st.session_state.chat_messages)}_{i}"):
175
+ st.session_state.last_suggestions = []
176
+ st.session_state.pending_q = sug
177
+ st.rerun()
178
+
179
  # Input
180
  is_ar = st.session_state.get("lang", "ar") == "ar"
181
  placeholder = "اسأل عن المناظرات، الشروط، أو إجراءات التكوين..." if is_ar else "Posez des questions sur les concours, conditions ou procédures..."
 
219
 
220
  st.markdown(full_response)
221
 
222
+ # ══ اقتراحات ذكية نحفظها في session_state قبل rerun ══
223
  if tool_used not in ("chat", "ask_user_profile") and not result.get("needs_user_input"):
224
  with st.spinner("💡 ..."):
225
  suggestions = agent.generate_suggestions(final_q, full_response, lang)
226
+ st.session_state.last_suggestions = suggestions if suggestions else []
227
+ else:
228
+ st.session_state.last_suggestions = []
 
 
 
 
 
229
 
230
  st.session_state.chat_messages.append({"role": "assistant", "content": full_response})
231
  st.session_state.last_tool = tool_used