Spaces:
Runtime error
Runtime error
Download app.py from RKIyer/figuring-out: direct link, hf CLI and curl.
- Browser
- Download file 1.03 kB
-
https://huggingface.co/spaces/RKIyer/figuring-out/resolve/main/app.py
- Command line
-
hf download hf://spaces/RKIyer/figuring-out/app.py
-
curl -L -o app.py https://huggingface.co/spaces/RKIyer/figuring-out/resolve/main/app.py
1.03 kB
| import gradio as gr | |
| def calculator(a, b, operation): | |
| try: | |
| a = float(a) | |
| b = float(b) | |
| if operation == "Add": | |
| return a + b | |
| elif operation == "Subtract": | |
| return a - b | |
| elif operation == "Multiply": | |
| return a * b | |
| elif operation == "Divide": | |
| if b != 0: | |
| return a / b | |
| else: | |
| return "Error: Division by zero" | |
| else: | |
| return "Invalid operation" | |
| except ValueError: | |
| return "Error: Invalid input" | |
| # Gradio Interface | |
| dropdown = gr.Dropdown(["Add", "Subtract", "Multiply", "Divide"], label="Operation") | |
| num1 = gr.Textbox(label="Enter first number", type="number") | |
| num2 = gr.Textbox(label="Enter second number", type="number") | |
| iface = gr.Interface( | |
| fn=calculator, | |
| inputs=[num1, num2, dropdown], | |
| outputs="text", | |
| title="Simple Calculator", | |
| description="Perform basic arithmetic operations. Enter two numbers and select an operation." | |
| ) | |
| iface.launch() | |