reddmann007 commited on
Commit
09c213c
·
verified ·
1 Parent(s): 9e67cde

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +19 -20
app.py CHANGED
@@ -69,28 +69,27 @@ for message in st.session_state.messages:
69
  with st.chat_message(message["role"]):
70
  st.markdown(message["content"])
71
 
72
- # --- 6. The Solve Action ---
73
- if st.button("🚀 Solve with AI", type="primary", use_container_width=True):
74
- if st.session_state.equation:
75
- user_input = st.session_state.equation
76
- st.session_state.messages.append({"role": "user", "content": user_input})
77
-
78
- with st.chat_message("assistant"):
79
- # --- START OF TRY BLOCK ---
 
 
80
  try:
81
- # This is the line that actually "runs" the math
 
82
  response = agent_executor.invoke({
83
- "messages": [system_message, ("user", user_input)]
84
  })
85
- answer = response["messages"][-1].content
86
- st.markdown(answer)
87
- st.session_state.messages.append({"role": "assistant", "content": answer})
88
- st.session_state.equation = ""
89
-
90
- except ZeroDivisionError:
91
- st.error("🚫 Mathematicians have determined that division by zero is undefined! Try a different calculation.")
92
 
93
  except Exception as e:
94
- # This catches other errors like "Unknown format" or "Timeout"
95
- st.warning(f"⚠️ I ran into a bit of a snag: {e}")
96
- # --- END OF TRY BLOCK ---
 
69
  with st.chat_message(message["role"]):
70
  st.markdown(message["content"])
71
 
72
+ # 6. User Input Logic
73
+ if prompt := st.chat_input("Ask me a complex math question!"):
74
+ # Add user message to history
75
+ st.session_state.messages.append({"role": "user", "content": prompt})
76
+ with st.chat_message("user"):
77
+ st.markdown(prompt)
78
+
79
+ # Generate Agent Response
80
+ with st.chat_message("assistant"):
81
+ with st.spinner("Thinking..."):
82
  try:
83
+ # ALL lines below 'try' must be indented 4 spaces further
84
+ # We pass the system_message rules directly here
85
  response = agent_executor.invoke({
86
+ "messages": [system_message, ("user", prompt)]
87
  })
88
+
89
+ final_answer = response["messages"][-1].content
90
+
91
+ st.markdown(final_answer)
92
+ st.session_state.messages.append({"role": "assistant", "content": final_answer})
 
 
93
 
94
  except Exception as e:
95
+ st.error(f"An error occurred: {e}")