Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,55 +1,57 @@
|
|
| 1 |
import streamlit as st
|
| 2 |
import sympy as sp
|
| 3 |
import re
|
| 4 |
-
from sympy.ntheory.modular import solve_linear_congruence
|
| 5 |
|
| 6 |
# 1. SETUP
|
| 7 |
st.set_page_config(page_title="SAAD AI ACADEMY", layout="centered")
|
| 8 |
|
| 9 |
-
# 2. THE
|
| 10 |
def universal_solver(query):
|
| 11 |
try:
|
| 12 |
-
|
|
|
|
|
|
|
| 13 |
if "mod" in query.lower():
|
| 14 |
nums = re.findall(r'\d+', query)
|
| 15 |
if len(nums) >= 3:
|
| 16 |
a, b, n = map(int, nums[:3])
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 35 |
|
| 36 |
except Exception as e:
|
| 37 |
-
return f"
|
| 38 |
|
| 39 |
# 3. UI
|
| 40 |
st.title("📐 SAAD AI ACADEMY")
|
| 41 |
-
st.
|
| 42 |
-
|
| 43 |
-
user_input = st.text_input("Input:", placeholder="e.g. diff(sin(x)*exp(x), x) or x**2 - 5*x + 6 = 0")
|
| 44 |
|
| 45 |
if user_input:
|
| 46 |
result = universal_solver(user_input)
|
| 47 |
st.divider()
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
st.latex(sp.latex(result))
|
| 51 |
else:
|
| 52 |
-
st.
|
| 53 |
|
| 54 |
# 4. SIDEBAR
|
| 55 |
-
st.sidebar.info("
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
import sympy as sp
|
| 3 |
import re
|
|
|
|
| 4 |
|
| 5 |
# 1. SETUP
|
| 6 |
st.set_page_config(page_title="SAAD AI ACADEMY", layout="centered")
|
| 7 |
|
| 8 |
+
# 2. THE STABLE SOLVER
|
| 9 |
def universal_solver(query):
|
| 10 |
try:
|
| 11 |
+
x = sp.Symbol('x')
|
| 12 |
+
|
| 13 |
+
# A. MODULAR CONGRUENCE (The 14x = 30 mod 44 logic)
|
| 14 |
if "mod" in query.lower():
|
| 15 |
nums = re.findall(r'\d+', query)
|
| 16 |
if len(nums) >= 3:
|
| 17 |
a, b, n = map(int, nums[:3])
|
| 18 |
+
# Using solveset on a modular equation is the most stable way
|
| 19 |
+
equation = sp.Eq(sp.Mod(a*x, n), b % n)
|
| 20 |
+
sol = sp.solveset(equation, x, domain=sp.S.Integers)
|
| 21 |
+
return f"Result: ${sp.latex(sol)}$"
|
| 22 |
+
|
| 23 |
+
# B. CALCULUS (Derivatives/Integrals)
|
| 24 |
+
if "diff" in query.lower() or "derivative" in query.lower():
|
| 25 |
+
expr = sp.sympify(query.split("of")[-1].strip())
|
| 26 |
+
return sp.diff(expr, x)
|
| 27 |
+
|
| 28 |
+
if "integrate" in query.lower():
|
| 29 |
+
expr = sp.sympify(query.split("integrate")[-1].strip())
|
| 30 |
+
return sp.integrate(expr, x)
|
| 31 |
+
|
| 32 |
+
# C. GENERAL ALGEBRA
|
| 33 |
+
clean_query = query.replace("solve", "").replace("find", "").strip()
|
| 34 |
+
if "=" in clean_query:
|
| 35 |
+
parts = clean_query.split("=")
|
| 36 |
+
eq = sp.Eq(sp.sympify(parts[0]), sp.sympify(parts[1]))
|
| 37 |
+
return sp.solve(eq, x)
|
| 38 |
+
|
| 39 |
+
return sp.simplify(sp.sympify(clean_query))
|
| 40 |
|
| 41 |
except Exception as e:
|
| 42 |
+
return f"Please check syntax. Use x**2 for powers. Error: {e}"
|
| 43 |
|
| 44 |
# 3. UI
|
| 45 |
st.title("📐 SAAD AI ACADEMY")
|
| 46 |
+
user_input = st.text_input("Enter problem:", placeholder="e.g. 14x = 30 mod 44")
|
|
|
|
|
|
|
| 47 |
|
| 48 |
if user_input:
|
| 49 |
result = universal_solver(user_input)
|
| 50 |
st.divider()
|
| 51 |
+
if isinstance(result, str) and "Result" in result:
|
| 52 |
+
st.markdown(result)
|
|
|
|
| 53 |
else:
|
| 54 |
+
st.latex(sp.latex(result))
|
| 55 |
|
| 56 |
# 4. SIDEBAR
|
| 57 |
+
st.sidebar.info("v6.1: Stable Solver (Python 3.13 Ready)")
|