Spaces:
Sleeping
Sleeping
Commit
·
db456d9
1
Parent(s):
1570b4f
Create fib.py
Browse files
fib.py
ADDED
@@ -0,0 +1,32 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
|
3 |
+
def fibonacci(n):
|
4 |
+
"""
|
5 |
+
Generate the Fibonacci sequence up to the nth term.
|
6 |
+
|
7 |
+
Parameters:
|
8 |
+
- n (int): The number of terms to generate in the Fibonacci sequence.
|
9 |
+
|
10 |
+
Returns:
|
11 |
+
- List[int]: A list containing the Fibonacci sequence.
|
12 |
+
"""
|
13 |
+
fib_sequence = [0, 1]
|
14 |
+
|
15 |
+
while len(fib_sequence) < n:
|
16 |
+
fib_sequence.append(fib_sequence[-1] + fib_sequence[-2])
|
17 |
+
|
18 |
+
return fib_sequence
|
19 |
+
|
20 |
+
# Create a Gradio interface
|
21 |
+
iface = gr.Interface(
|
22 |
+
fn=fibonacci,
|
23 |
+
inputs=gr.Number(),
|
24 |
+
outputs=gr.Textbox(),
|
25 |
+
live=True,
|
26 |
+
theme="compact",
|
27 |
+
title="Fibonacci Sequence Generator",
|
28 |
+
description="Enter the number of terms to generate in the Fibonacci sequence:",
|
29 |
+
)
|
30 |
+
|
31 |
+
# Launch the Gradio interface
|
32 |
+
iface.launch()
|