Anshini commited on
Commit
51211ad
·
verified ·
1 Parent(s): 819981a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +17 -3
app.py CHANGED
@@ -215,7 +215,12 @@ if "chat_history" not in st.session_state:
215
  for msg in st.session_state.chat_history:
216
  role = "user" if isinstance(msg, HumanMessage) else "bot"
217
  st.markdown(f"<div class='stChatMessage {role}'>{msg.content}</div>", unsafe_allow_html=True)
218
-
 
 
 
 
 
219
  # Custom Chat Input Box UI
220
  with st.container():
221
  with st.form("chat_form", clear_on_submit=True):
@@ -235,10 +240,19 @@ with st.container():
235
  }
236
 
237
  result = graph.invoke(state_input, config=config)
 
 
 
 
 
 
238
  if result.get("code"):
 
239
  st.session_state.chat_history.append(AIMessage(content=result["code"]))
240
- elif result.get("explanation"):
241
- st.session_state.chat_history.append(AIMessage(content=result["explanation"]))
 
 
242
  elif result.get("messages"):
243
  st.session_state.chat_history.append(result["messages"][-1])
244
 
 
215
  for msg in st.session_state.chat_history:
216
  role = "user" if isinstance(msg, HumanMessage) else "bot"
217
  st.markdown(f"<div class='stChatMessage {role}'>{msg.content}</div>", unsafe_allow_html=True)
218
+
219
+ # Show explanation button if code exists
220
+ if "latest_explanation" in st.session_state:
221
+ with st.expander("🔍 Show Code Explanation"):
222
+ st.markdown(f"<div class='stChatMessage bot'>**🔍 Code Explanation:**<br><br>{st.session_state.latest_explanation}</div>", unsafe_allow_html=True)
223
+
224
  # Custom Chat Input Box UI
225
  with st.container():
226
  with st.form("chat_form", clear_on_submit=True):
 
240
  }
241
 
242
  result = graph.invoke(state_input, config=config)
243
+ # if result.get("code"):
244
+ # st.session_state.chat_history.append(AIMessage(content=result["code"]))
245
+ # elif result.get("explanation"):
246
+ # st.session_state.chat_history.append(AIMessage(content=result["explanation"]))
247
+ # elif result.get("messages"):
248
+ # st.session_state.chat_history.append(result["messages"][-1])
249
  if result.get("code"):
250
+ st.session_state.latest_code = result["code"]
251
  st.session_state.chat_history.append(AIMessage(content=result["code"]))
252
+
253
+ if result.get("explanation"):
254
+ st.session_state.latest_explanation = result["explanation"]
255
+
256
  elif result.get("messages"):
257
  st.session_state.chat_history.append(result["messages"][-1])
258