File size: 852 Bytes
af56c98
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
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()