Spaces:
Sleeping
Sleeping
| import gradio as gr | |
| import math | |
| # 1. Write the function | |
| def math_superpowers(number): | |
| """ | |
| Takes a number and returns its square, cube, and factorial. | |
| """ | |
| if number is None: | |
| return None, None, None | |
| # Check if the number is a negative integer or float for factorial safety | |
| # (Factorial generally requires non-negative integers) | |
| if number < 0 or not number.is_integer(): | |
| return number**2, number**3, "Factorial requires a non-negative integer" | |
| val = int(number) | |
| square = val ** 2 | |
| cube = val ** 3 | |
| factorial = math.factorial(val) | |
| # Return as a list/tuple to populate multiple output boxes | |
| return square, cube, factorial | |
| # 2. Wrap the function in a Gradio Interface | |
| # We map 1 input to 3 outputs | |
| demo = gr.Interface( | |
| fn=math_superpowers, | |
| inputs=gr.Number(label="Enter a Number"), | |
| outputs=[ | |
| gr.Number(label="Square"), | |
| gr.Number(label="Cube"), | |
| gr.Number(label="Factorial") | |
| ], | |
| title="Math Superpowers Calculator", | |
| description="Enter a number to see its Square, Cube, and Factorial instantly!" | |
| ) | |
| # 3. Launch the app with share=True as requested | |
| demo.launch(share=True) |