Spaces:
Build error
Build error
quicklearnmath
Browse filesstreamlit
sympy
app.py
CHANGED
|
@@ -1,11 +1,11 @@
|
|
| 1 |
-
import
|
| 2 |
import sympy as sp
|
| 3 |
|
| 4 |
# Function to solve algebraic equations
|
| 5 |
def solve_equation(equation):
|
| 6 |
lhs, rhs = equation.split("=")
|
| 7 |
lhs = sp.sympify(lhs)
|
| 8 |
-
rhs = sp.sympify(rhs)
|
| 9 |
solution = sp.solve(lhs - rhs)
|
| 10 |
return f"Solution: {solution}"
|
| 11 |
|
|
@@ -36,38 +36,52 @@ def solve_word_problem(operation, num1, num2):
|
|
| 36 |
result = num1 / num2
|
| 37 |
return f"Result: {result}"
|
| 38 |
|
| 39 |
-
#
|
| 40 |
-
def
|
| 41 |
-
|
| 42 |
-
gr.Markdown("# Math Problem-Solution App")
|
| 43 |
-
|
| 44 |
-
with gr.Tab("Solve Algebraic Equation"):
|
| 45 |
-
equation_input = gr.Textbox(label="Enter an equation (e.g., 2*x + 3 = 5)", lines=1)
|
| 46 |
-
solve_button = gr.Button("Solve Equation")
|
| 47 |
-
solution_output = gr.Textbox(label="Solution", interactive=False)
|
| 48 |
-
solve_button.click(solve_equation, inputs=equation_input, outputs=solution_output)
|
| 49 |
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
simplify_button = gr.Button("Simplify")
|
| 53 |
-
simplified_output = gr.Textbox(label="Simplified Expression", interactive=False)
|
| 54 |
-
simplify_button.click(simplify_expression, inputs=expression_input, outputs=simplified_output)
|
| 55 |
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 61 |
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
|
| 71 |
|
| 72 |
-
|
| 73 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
import sympy as sp
|
| 3 |
|
| 4 |
# Function to solve algebraic equations
|
| 5 |
def solve_equation(equation):
|
| 6 |
lhs, rhs = equation.split("=")
|
| 7 |
lhs = sp.sympify(lhs)
|
| 8 |
+
rhs = sp.sympify(rhs)
|
| 9 |
solution = sp.solve(lhs - rhs)
|
| 10 |
return f"Solution: {solution}"
|
| 11 |
|
|
|
|
| 36 |
result = num1 / num2
|
| 37 |
return f"Result: {result}"
|
| 38 |
|
| 39 |
+
# Streamlit Interface
|
| 40 |
+
def main():
|
| 41 |
+
st.title("Math Problem-Solution App")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 42 |
|
| 43 |
+
# Tabs for different functionalities
|
| 44 |
+
tab = st.radio("Select a problem type:", ["Solve Algebraic Equation", "Simplify Expression", "Factor Expression", "Solve Word Problem"])
|
|
|
|
|
|
|
|
|
|
| 45 |
|
| 46 |
+
if tab == "Solve Algebraic Equation":
|
| 47 |
+
st.header("Solve Algebraic Equation")
|
| 48 |
+
equation_input = st.text_input("Enter an equation (e.g., 2*x + 3 = 5)", "")
|
| 49 |
+
if st.button("Solve Equation"):
|
| 50 |
+
if equation_input:
|
| 51 |
+
solution = solve_equation(equation_input)
|
| 52 |
+
st.write(solution)
|
| 53 |
+
else:
|
| 54 |
+
st.write("Please enter an equation!")
|
| 55 |
|
| 56 |
+
elif tab == "Simplify Expression":
|
| 57 |
+
st.header("Simplify Expression")
|
| 58 |
+
expression_input = st.text_input("Enter an expression (e.g., 2*x + 3*x - 4)", "")
|
| 59 |
+
if st.button("Simplify Expression"):
|
| 60 |
+
if expression_input:
|
| 61 |
+
simplified_expr = simplify_expression(expression_input)
|
| 62 |
+
st.write(simplified_expr)
|
| 63 |
+
else:
|
| 64 |
+
st.write("Please enter an expression!")
|
| 65 |
|
| 66 |
+
elif tab == "Factor Expression":
|
| 67 |
+
st.header("Factor Expression")
|
| 68 |
+
factor_input = st.text_input("Enter an expression to factor (e.g., x^2 - 5*x + 6)", "")
|
| 69 |
+
if st.button("Factor Expression"):
|
| 70 |
+
if factor_input:
|
| 71 |
+
factored_expr = factor_expression(factor_input)
|
| 72 |
+
st.write(factored_expr)
|
| 73 |
+
else:
|
| 74 |
+
st.write("Please enter an expression!")
|
| 75 |
+
|
| 76 |
+
elif tab == "Solve Word Problem":
|
| 77 |
+
st.header("Solve Word Problem")
|
| 78 |
+
operation = st.selectbox("Choose an operation:", ["addition", "subtraction", "multiplication", "division"])
|
| 79 |
+
num1_input = st.number_input("Enter the first number", 0)
|
| 80 |
+
num2_input = st.number_input("Enter the second number", 0)
|
| 81 |
+
if st.button("Solve Word Problem"):
|
| 82 |
+
result = solve_word_problem(operation, num1_input, num2_input)
|
| 83 |
+
st.write(result)
|
| 84 |
+
|
| 85 |
+
# Run the app
|
| 86 |
+
if __name__ == "__main__":
|
| 87 |
+
main()
|