Spaces:
Sleeping
Sleeping
| import gradio as gr | |
| def find_gcd(a, b): | |
| x, y = a, b | |
| while y != 0: | |
| x, y = y, x % y | |
| return f"GCD of {a} and {b} is {x}" | |
| def find_lcm(a, b): | |
| if a == 0 or b == 0: | |
| return "LCM is 0" | |
| product = a * b | |
| x, y = a, b | |
| while y != 0: | |
| x, y = y, x % y | |
| lcm = abs(product) // x | |
| return f"LCM of {a} and {b} is {lcm}" | |
| def prime_factors(n): | |
| if n <= 1: | |
| return "No prime factors for numbers <= 1" | |
| factors = [] | |
| d = 2 | |
| while d * d <= n: | |
| while n % d == 0: | |
| factors.append(d) | |
| n //= d | |
| d += 1 | |
| if n > 1: | |
| factors.append(n) | |
| return f"Prime factors: {', '.join(map(str, factors))}" | |
| def handle_rating(rating): | |
| if int(rating) > 5: | |
| return "Thanks for the review!" | |
| else: | |
| return "Please share your issues at annasrshd@gmail.com. Thank you!" | |
| # Create interfaces | |
| gcd_interface = gr.Interface( | |
| fn=find_gcd, | |
| inputs=[gr.Number(label="First Number"), gr.Number(label="Second Number")], | |
| outputs="text", | |
| title="Find GCD" | |
| ) | |
| lcm_interface = gr.Interface( | |
| fn=find_lcm, | |
| inputs=[gr.Number(label="First Number"), gr.Number(label="Second Number")], | |
| outputs="text", | |
| title="Find LCM" | |
| ) | |
| prime_interface = gr.Interface( | |
| fn=prime_factors, | |
| inputs=gr.Number(label="Enter a Number"), | |
| outputs="text", | |
| title="Prime Factorization" | |
| ) | |
| rating_interface = gr.Interface( | |
| fn=handle_rating, | |
| inputs=gr.Slider(1, 10, step=1, label="Rate the project (1 to 10)"), | |
| outputs="text", | |
| title="Project Feedback" | |
| ) | |
| # Launch as tabs | |
| gr.TabbedInterface( | |
| [gcd_interface, lcm_interface, prime_interface, rating_interface], | |
| ["GCD", "LCM", "Prime Factorization", "Feedback"] | |
| ).launch() | |