ghaffarmumtat123 commited on
Commit
36c6d97
·
verified ·
1 Parent(s): 29c212c

quicklearnmath

Browse files

streamlit
sympy

Files changed (1) hide show
  1. app.py +47 -33
app.py CHANGED
@@ -1,11 +1,11 @@
1
- import gradio as gr
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) # Removed extra text
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
- # Create Gradio interface
40
- def create_interface():
41
- with gr.Blocks() as demo:
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
- with gr.Tab("Simplify Expression"):
51
- expression_input = gr.Textbox(label="Enter an expression (e.g., 2*x + 3*x - 4)", lines=1)
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
- with gr.Tab("Factor Expression"):
57
- factor_input = gr.Textbox(label="Enter an expression to factor (e.g., x^2 - 5*x + 6)", lines=1)
58
- factor_button = gr.Button("Factor Expression")
59
- factored_output = gr.Textbox(label="Factored Expression", interactive=False)
60
- factor_button.click(factor_expression, inputs=factor_input, outputs=factored_output)
 
 
 
 
61
 
62
- with gr.Tab("Solve Word Problem"):
63
- operation_dropdown = gr.Dropdown(choices=["addition", "subtraction", "multiplication", "division"], label="Operation")
64
- num1_input = gr.Number(label="Enter the first number")
65
- num2_input = gr.Number(label="Enter the second number")
66
- word_button = gr.Button("Solve Word Problem")
67
- word_output = gr.Textbox(label="Result", interactive=False)
68
- word_button.click(solve_word_problem, inputs=[operation_dropdown, num1_input, num2_input], outputs=word_output)
69
-
70
- demo.launch()
71
 
72
- # Run the interface
73
- create_interface()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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()