Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,6 +1,6 @@
|
|
1 |
import streamlit as st
|
2 |
from sympy import (
|
3 |
-
symbols, integrate, diff, exp, log, ln, sin, cos, tan, sec, csc, cot, latex
|
4 |
)
|
5 |
|
6 |
# Define the Streamlit app
|
@@ -20,14 +20,13 @@ def main():
|
|
20 |
# Input section
|
21 |
st.header("Input the Function")
|
22 |
function_input = st.text_input(
|
23 |
-
"Enter the integrand (e.g., x * exp(x), ln(x), x^2 *
|
24 |
"x * exp(x)",
|
25 |
)
|
26 |
u_input = st.text_input(
|
27 |
"Choose 'u' (e.g., x for x * exp(x) or ln(x)):", "x"
|
28 |
)
|
29 |
|
30 |
-
# Solve button
|
31 |
if st.button("Solve"):
|
32 |
try:
|
33 |
# Define the variable and import common functions for eval()
|
@@ -36,9 +35,14 @@ def main():
|
|
36 |
"sin": sin, "cos": cos, "tan": tan,
|
37 |
"sec": sec, "csc": csc, "cot": cot}
|
38 |
|
39 |
-
#
|
40 |
-
|
41 |
-
|
|
|
|
|
|
|
|
|
|
|
42 |
dv = integrand / u
|
43 |
|
44 |
# Compute derivatives and integrals
|
|
|
1 |
import streamlit as st
|
2 |
from sympy import (
|
3 |
+
symbols, integrate, diff, exp, log, ln, sin, cos, tan, sec, csc, cot, latex, SympifyError, sympify
|
4 |
)
|
5 |
|
6 |
# Define the Streamlit app
|
|
|
20 |
# Input section
|
21 |
st.header("Input the Function")
|
22 |
function_input = st.text_input(
|
23 |
+
"Enter the integrand (e.g., x * exp(x), cos(ln(x)), x^2 * sin(x)):",
|
24 |
"x * exp(x)",
|
25 |
)
|
26 |
u_input = st.text_input(
|
27 |
"Choose 'u' (e.g., x for x * exp(x) or ln(x)):", "x"
|
28 |
)
|
29 |
|
|
|
30 |
if st.button("Solve"):
|
31 |
try:
|
32 |
# Define the variable and import common functions for eval()
|
|
|
35 |
"sin": sin, "cos": cos, "tan": tan,
|
36 |
"sec": sec, "csc": csc, "cot": cot}
|
37 |
|
38 |
+
# Validate and parse inputs
|
39 |
+
try:
|
40 |
+
integrand = sympify(function_input, locals=safe_globals)
|
41 |
+
u = sympify(u_input, locals=safe_globals)
|
42 |
+
except SympifyError:
|
43 |
+
st.error("Invalid input. Please use valid mathematical syntax (e.g., cos(ln(x))).")
|
44 |
+
return
|
45 |
+
|
46 |
dv = integrand / u
|
47 |
|
48 |
# Compute derivatives and integrals
|