Spaces:
Sleeping
Sleeping
| import gradio as gr | |
| import re | |
| BOT_NAME = "Phu Quy Ho" | |
| def handle_math(user_input): | |
| user_input = user_input.lower().strip() | |
| # Respond to greetings | |
| greetings = ["hi", "hello", "hey", "yo"] | |
| if any(greet in user_input for greet in greetings): | |
| return f"Hello! I am {BOT_NAME}. I can help you with math. Try something like: (3 + 5) * -2" | |
| # Remove everything except math symbols and numbers | |
| math_expression = re.sub(r"[^\d\.\+\-\*/\(\)\s]", "", user_input) | |
| math_expression = math_expression.replace("what is", "").strip() | |
| try: | |
| result = eval(math_expression) | |
| return f"The answer is {result}" | |
| except: | |
| return "Sorry, I couldn't understand that. Please enter a valid math expression like (2 + 3) * -1" | |
| # Gradio UI | |
| demo = gr.Interface( | |
| fn=handle_math, | |
| inputs="text", | |
| outputs="text", | |
| title="Phu Quy Ho – Smart Math Solver", | |
| description="Say hello or ask me a math question! I support +, -, *, /, negative numbers, and parentheses." | |
| ) | |
| demo.launch() |