Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,62 +1,76 @@
|
|
| 1 |
import streamlit as st
|
| 2 |
-
|
| 3 |
-
import
|
| 4 |
|
| 5 |
# 1. PAGE CONFIG
|
| 6 |
-
st.set_page_config(page_title="SAAD AI ACADEMY",
|
| 7 |
|
| 8 |
-
# 2. DARK
|
| 9 |
st.markdown("""
|
| 10 |
<style>
|
| 11 |
-
.stApp { background:
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
.stCaption { color: #3b82f6 !important; }
|
| 15 |
</style>
|
| 16 |
""", unsafe_allow_html=True)
|
| 17 |
|
| 18 |
st.title("π SAAD AI ACADEMY")
|
| 19 |
-
st.
|
| 20 |
-
|
| 21 |
-
# 3.
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
#
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
)
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 60 |
st.sidebar.write("**Name:** Almuyed Saad")
|
| 61 |
st.sidebar.write("**Inst:** SUST")
|
| 62 |
-
st.sidebar.
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
+
import sympy as sp
|
| 3 |
+
import re
|
| 4 |
|
| 5 |
# 1. PAGE CONFIG
|
| 6 |
+
st.set_page_config(page_title="SAAD AI ACADEMY", layout="centered")
|
| 7 |
|
| 8 |
+
# 2. DARK UI
|
| 9 |
st.markdown("""
|
| 10 |
<style>
|
| 11 |
+
.stApp { background: #0f172a; color: white; }
|
| 12 |
+
h1, h2, h3 { color: #3b82f6 !important; }
|
| 13 |
+
.stTextInput > div > div > input { background-color: #1e293b; color: white; border: 1px solid #3b82f6; }
|
|
|
|
| 14 |
</style>
|
| 15 |
""", unsafe_allow_html=True)
|
| 16 |
|
| 17 |
st.title("π SAAD AI ACADEMY")
|
| 18 |
+
st.subheader("B.Sc. Math Engine v6.0 (Zero-Error Logic)")
|
| 19 |
+
|
| 20 |
+
# 3. COMPUTATION ENGINE
|
| 21 |
+
def solve_math(query):
|
| 22 |
+
try:
|
| 23 |
+
x = sp.Symbol('x')
|
| 24 |
+
|
| 25 |
+
# A. HANDLE LINEAR CONGRUENCE: "solve 14x = 30 mod 44"
|
| 26 |
+
if "mod" in query.lower():
|
| 27 |
+
# Extract numbers using Regex
|
| 28 |
+
nums = re.findall(r'\d+', query)
|
| 29 |
+
if len(nums) >= 3:
|
| 30 |
+
a, b, n = map(int, nums[:3])
|
| 31 |
+
# SymPy's solver for ax β‘ b (mod n)
|
| 32 |
+
solutions = sp.solve_linear_congruence(a, b, n)
|
| 33 |
+
return f"The solutions are: x \equiv {solutions} \pmod{{{n}}}"
|
| 34 |
+
return "Format error. Try: 'solve 14x = 30 mod 44'"
|
| 35 |
+
|
| 36 |
+
# B. HANDLE DERIVATIVES: "derivative of x**2 + 5*x"
|
| 37 |
+
if "derivative" in query.lower() or "diff" in query.lower():
|
| 38 |
+
expr_str = query.split("of")[-1].strip()
|
| 39 |
+
expr = sp.sympify(expr_str)
|
| 40 |
+
return sp.diff(expr, x)
|
| 41 |
+
|
| 42 |
+
# C. HANDLE INTEGRALS: "integrate x**2"
|
| 43 |
+
if "integrate" in query.lower():
|
| 44 |
+
expr_str = query.split("integrate")[-1].strip()
|
| 45 |
+
expr = sp.sympify(expr_str)
|
| 46 |
+
return sp.integrate(expr, x)
|
| 47 |
+
|
| 48 |
+
# D. GENERAL SOLVE: "solve x**2 - 4"
|
| 49 |
+
if "solve" in query.lower() and "mod" not in query.lower():
|
| 50 |
+
expr_str = query.split("solve")[-1].strip()
|
| 51 |
+
expr = sp.sympify(expr_str)
|
| 52 |
+
return sp.solve(expr, x)
|
| 53 |
+
|
| 54 |
+
return "I can solve Congruences, Derivatives, Integrals, and Equations. Please be specific!"
|
| 55 |
+
|
| 56 |
+
except Exception as e:
|
| 57 |
+
return f"Logic Error: {e}. Please use Python syntax like x**2 for xΒ²."
|
| 58 |
+
|
| 59 |
+
# 4. INTERFACE
|
| 60 |
+
user_input = st.text_input("Enter your problem:", placeholder="e.g., solve 14x = 30 mod 44")
|
| 61 |
+
|
| 62 |
+
if user_input:
|
| 63 |
+
res = solve_math(user_input)
|
| 64 |
+
st.markdown("---")
|
| 65 |
+
st.markdown("### π― Result:")
|
| 66 |
+
if isinstance(res, str):
|
| 67 |
+
st.info(res)
|
| 68 |
+
else:
|
| 69 |
+
# Display as beautiful LaTeX
|
| 70 |
+
st.latex(sp.latex(res))
|
| 71 |
+
|
| 72 |
+
# 5. SIDEBAR
|
| 73 |
+
st.sidebar.markdown("### π Academic Profile")
|
| 74 |
st.sidebar.write("**Name:** Almuyed Saad")
|
| 75 |
st.sidebar.write("**Inst:** SUST")
|
| 76 |
+
st.sidebar.info("This engine uses SymPy for symbolic math, ensuring 100% precision for B.Sc. coursework.")
|