Spaces:
Runtime error
Runtime error
| import streamlit as st | |
| import sympy as sp | |
| import re | |
| # 1. SETUP | |
| st.set_page_config(page_title="SAAD AI ACADEMY", layout="centered") | |
| # 2. THE STABLE SOLVER | |
| def universal_solver(query): | |
| try: | |
| x = sp.Symbol('x') | |
| # A. MODULAR CONGRUENCE (The 14x = 30 mod 44 logic) | |
| if "mod" in query.lower(): | |
| nums = re.findall(r'\d+', query) | |
| if len(nums) >= 3: | |
| a, b, n = map(int, nums[:3]) | |
| # Using solveset on a modular equation is the most stable way | |
| equation = sp.Eq(sp.Mod(a*x, n), b % n) | |
| sol = sp.solveset(equation, x, domain=sp.S.Integers) | |
| return f"Result: ${sp.latex(sol)}$" | |
| # B. CALCULUS (Derivatives/Integrals) | |
| if "diff" in query.lower() or "derivative" in query.lower(): | |
| expr = sp.sympify(query.split("of")[-1].strip()) | |
| return sp.diff(expr, x) | |
| if "integrate" in query.lower(): | |
| expr = sp.sympify(query.split("integrate")[-1].strip()) | |
| return sp.integrate(expr, x) | |
| # C. GENERAL ALGEBRA | |
| clean_query = query.replace("solve", "").replace("find", "").strip() | |
| if "=" in clean_query: | |
| parts = clean_query.split("=") | |
| eq = sp.Eq(sp.sympify(parts[0]), sp.sympify(parts[1])) | |
| return sp.solve(eq, x) | |
| return sp.simplify(sp.sympify(clean_query)) | |
| except Exception as e: | |
| return f"Please check syntax. Use x**2 for powers. Error: {e}" | |
| # 3. UI | |
| st.title("๐ SAAD AI ACADEMY") | |
| user_input = st.text_input("Enter problem:", placeholder="e.g. 14x = 30 mod 44") | |
| if user_input: | |
| result = universal_solver(user_input) | |
| st.divider() | |
| if isinstance(result, str) and "Result" in result: | |
| st.markdown(result) | |
| else: | |
| st.latex(sp.latex(result)) | |
| # 4. SIDEBAR | |
| st.sidebar.info("v6.1: Stable Solver (Python 3.13 Ready)") |