Download app.py from Haseeb005/cal: direct link, hf CLI and curl.
- Browser
- Download file 735 Bytes
-
https://huggingface.co/spaces/Haseeb005/cal/resolve/main/app.py
- Command line
-
hf download hf://spaces/Haseeb005/cal/app.py
-
curl -L -o app.py https://huggingface.co/spaces/Haseeb005/cal/resolve/main/app.py
735 Bytes
| import gradio as gr | |
| def calculator(operation, a, 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 "Cannot divide by zero" | |
| return a / b | |
| else: | |
| return "Invalid operation" | |
| demo = gr.Interface( | |
| fn=calculator, | |
| inputs=[ | |
| gr.Radio(["Add", "Subtract", "Multiply", "Divide"], label="Operation"), | |
| gr.Number(label="Input A"), | |
| gr.Number(label="Input B") | |
| ], | |
| outputs="text", | |
| title="Demo Calculator", | |
| description="Perform basic arithmetic operations." | |
| ) | |
| if __name__ == "__main__": | |
| demo.launch() |