ALgebraBot / app.py
DGRDN's picture
Create app.py
af56c98 verified
Raw History Blame Contribute Delete
852 Bytes
import gradio as gr
from sympy import symbols, Eq, solve
x, y = symbols('x y')
def solve_system(eq1_str, eq2_str):
try:
# Evaluate the equations safely
eq1 = eval(eq1_str)
eq2 = eval(eq2_str)
solution = solve((eq1, eq2), (x, y))
if not solution:
return "❌ No solution found. Check your equations."
return f"✅ Solution:\nx = {solution[x]}\ny = {solution[y]}"
except Exception as e:
return f"⚠️ Error: {str(e)}"
demo = gr.Interface(
fn=solve_system,
inputs=[
gr.Textbox(label="Equation 1 (e.g., Eq(2*x + 3*y, 12))"),
gr.Textbox(label="Equation 2 (e.g., Eq(x - y, 3))")
],
outputs="text",
title="🧮 Two-Variable Algebra Solver",
description="Enter two equations using SymPy syntax. Example: Eq(2*x + 3*y, 12)"
)
demo.launch()