Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,51 +1,72 @@
|
|
| 1 |
-
|
| 2 |
-
|
| 3 |
-
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
if
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
if n > 1:
|
| 37 |
-
print(n)
|
| 38 |
-
else:
|
| 39 |
-
print()
|
| 40 |
-
|
| 41 |
-
elif choice == '4':
|
| 42 |
-
print("Goodbye!")
|
| 43 |
-
|
| 44 |
else:
|
| 45 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 46 |
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
|
| 3 |
+
def find_gcd(a, b):
|
| 4 |
+
x, y = a, b
|
| 5 |
+
while y != 0:
|
| 6 |
+
x, y = y, x % y
|
| 7 |
+
return f"GCD of {a} and {b} is {x}"
|
| 8 |
+
|
| 9 |
+
def find_lcm(a, b):
|
| 10 |
+
if a == 0 or b == 0:
|
| 11 |
+
return "LCM is 0"
|
| 12 |
+
product = a * b
|
| 13 |
+
x, y = a, b
|
| 14 |
+
while y != 0:
|
| 15 |
+
x, y = y, x % y
|
| 16 |
+
lcm = abs(product) // x
|
| 17 |
+
return f"LCM of {a} and {b} is {lcm}"
|
| 18 |
+
|
| 19 |
+
def prime_factors(n):
|
| 20 |
+
if n <= 1:
|
| 21 |
+
return "No prime factors for numbers <= 1"
|
| 22 |
+
factors = []
|
| 23 |
+
d = 2
|
| 24 |
+
while d * d <= n:
|
| 25 |
+
while n % d == 0:
|
| 26 |
+
factors.append(d)
|
| 27 |
+
n //= d
|
| 28 |
+
d += 1
|
| 29 |
+
if n > 1:
|
| 30 |
+
factors.append(n)
|
| 31 |
+
return f"Prime factors: {', '.join(map(str, factors))}"
|
| 32 |
+
|
| 33 |
+
def handle_rating(rating):
|
| 34 |
+
if int(rating) > 5:
|
| 35 |
+
return "Thanks for the review!"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 36 |
else:
|
| 37 |
+
return "Please share your issues at annasrshd@gmail.com. Thank you!"
|
| 38 |
+
|
| 39 |
+
# Create interfaces
|
| 40 |
+
gcd_interface = gr.Interface(
|
| 41 |
+
fn=find_gcd,
|
| 42 |
+
inputs=[gr.Number(label="First Number"), gr.Number(label="Second Number")],
|
| 43 |
+
outputs="text",
|
| 44 |
+
title="Find GCD"
|
| 45 |
+
)
|
| 46 |
+
|
| 47 |
+
lcm_interface = gr.Interface(
|
| 48 |
+
fn=find_lcm,
|
| 49 |
+
inputs=[gr.Number(label="First Number"), gr.Number(label="Second Number")],
|
| 50 |
+
outputs="text",
|
| 51 |
+
title="Find LCM"
|
| 52 |
+
)
|
| 53 |
+
|
| 54 |
+
prime_interface = gr.Interface(
|
| 55 |
+
fn=prime_factors,
|
| 56 |
+
inputs=gr.Number(label="Enter a Number"),
|
| 57 |
+
outputs="text",
|
| 58 |
+
title="Prime Factorization"
|
| 59 |
+
)
|
| 60 |
+
|
| 61 |
+
rating_interface = gr.Interface(
|
| 62 |
+
fn=handle_rating,
|
| 63 |
+
inputs=gr.Slider(1, 10, step=1, label="Rate the project (1 to 10)"),
|
| 64 |
+
outputs="text",
|
| 65 |
+
title="Project Feedback"
|
| 66 |
+
)
|
| 67 |
|
| 68 |
+
# Launch as tabs
|
| 69 |
+
gr.TabbedInterface(
|
| 70 |
+
[gcd_interface, lcm_interface, prime_interface, rating_interface],
|
| 71 |
+
["GCD", "LCM", "Prime Factorization", "Feedback"]
|
| 72 |
+
).launch()
|