Spaces:
Runtime error
Runtime error
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import time
|
| 3 |
+
|
| 4 |
+
def is_prime(n):
|
| 5 |
+
if n < 2:
|
| 6 |
+
return False
|
| 7 |
+
for i in range(2, int(n**0.5) + 1):
|
| 8 |
+
if n % i == 0:
|
| 9 |
+
return False
|
| 10 |
+
return True
|
| 11 |
+
|
| 12 |
+
def prime_generator():
|
| 13 |
+
num = 2
|
| 14 |
+
while True:
|
| 15 |
+
if is_prime(num):
|
| 16 |
+
yield str(num) # Yield the prime number as a string
|
| 17 |
+
num += 1
|
| 18 |
+
time.sleep(0.5) # Adjust the sleep time to control the speed of prime generation
|
| 19 |
+
|
| 20 |
+
def start_prime_printer():
|
| 21 |
+
prime_stream = prime_generator()
|
| 22 |
+
output = []
|
| 23 |
+
for prime in prime_stream:
|
| 24 |
+
output.append(prime)
|
| 25 |
+
yield "\n".join(output) # Update the output in the Gradio interface
|
| 26 |
+
|
| 27 |
+
# Gradio Interface
|
| 28 |
+
interface = gr.Interface(
|
| 29 |
+
fn=start_prime_printer, # Function to execute
|
| 30 |
+
inputs=None, # No input required
|
| 31 |
+
outputs="text", # Output type
|
| 32 |
+
live=True # Enable real-time updates
|
| 33 |
+
)
|
| 34 |
+
|
| 35 |
+
# Launch the interface
|
| 36 |
+
interface.launch()
|