Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -69,27 +69,28 @@ for message in st.session_state.messages:
|
|
| 69 |
with st.chat_message(message["role"]):
|
| 70 |
st.markdown(message["content"])
|
| 71 |
|
| 72 |
-
# 6.
|
| 73 |
-
if
|
| 74 |
-
|
| 75 |
-
|
| 76 |
-
|
| 77 |
-
|
| 78 |
-
|
| 79 |
-
|
| 80 |
-
with st.chat_message("assistant"):
|
| 81 |
-
with st.spinner("Thinking..."):
|
| 82 |
try:
|
| 83 |
-
#
|
| 84 |
-
# We pass the system_message rules directly here
|
| 85 |
response = agent_executor.invoke({
|
| 86 |
-
"messages": [system_message, ("user",
|
| 87 |
})
|
| 88 |
-
|
| 89 |
-
|
| 90 |
-
|
| 91 |
-
st.
|
| 92 |
-
|
|
|
|
|
|
|
| 93 |
|
| 94 |
except Exception as e:
|
| 95 |
-
|
|
|
|
|
|
|
|
|
| 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 ---
|