Download app.py from DGRDN/BotBoy: direct link, hf CLI and curl.
- Browser
- Download file 1.37 kB
-
https://huggingface.co/spaces/DGRDN/BotBoy/resolve/main/app.py
- Command line
-
hf download hf://spaces/DGRDN/BotBoy/app.py
-
curl -L -o app.py https://huggingface.co/spaces/DGRDN/BotBoy/resolve/main/app.py
1.37 kB
| import gradio as gr | |
| from sympy import symbols, Eq, solve, sympify | |
| x, y = symbols('x y') | |
| def parse_equation(eq_str): | |
| # Replace implicit multiplication (e.g., 2x → 2*x) | |
| eq_str = eq_str.replace(" ", "") | |
| eq_str = eq_str.replace("x", "*x").replace("y", "*y") | |
| eq_str = eq_str.replace("*x*x", "x*x").replace("*y*y", "y*y") # fix double stars | |
| eq_str = eq_str.replace("=*x", "=x").replace("=*y", "=y") # fix edge cases | |
| # Split into LHS and RHS | |
| if "=" not in eq_str: | |
| raise ValueError("Equation must contain '='") | |
| lhs, rhs = eq_str.split("=") | |
| return Eq(sympify(lhs), sympify(rhs)) | |
| def solve_system(eq1_str, eq2_str): | |
| try: | |
| eq1 = parse_equation(eq1_str) | |
| eq2 = parse_equation(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., 2x + 3y = 50)"), | |
| gr.Textbox(label="Equation 2 (e.g., 2x - 3y = 10)") | |
| ], | |
| outputs="text", | |
| title="🧮 Two-Variable Algebra Solver", | |
| description="Enter equations like 2x + 3y = 50. We'll auto-parse and solve them!" | |
| ) | |
| demo.launch() |