Spaces:
Sleeping
Sleeping
SunForever
commited on
Commit
•
cfc5425
1
Parent(s):
0bd6959
Update app.py
Browse files
app.py
CHANGED
@@ -1,37 +1,26 @@
|
|
1 |
-
# app.py
|
2 |
import gradio as gr
|
3 |
-
from celery import Celery
|
4 |
import time
|
5 |
-
import os
|
6 |
|
7 |
-
|
8 |
-
|
9 |
-
celery_app = Celery('tasks', broker=REDIS_URL)
|
10 |
-
|
11 |
-
@celery_app.task
|
12 |
-
def calculate_after_delay(expression):
|
13 |
-
time.sleep(6) # Wait 6 seconds
|
14 |
try:
|
15 |
-
result = eval(expression) #
|
16 |
return f"After 6 seconds, {expression} = {result}"
|
17 |
except:
|
18 |
return "Invalid math expression"
|
19 |
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
outputs=result
|
34 |
-
)
|
35 |
-
return demo
|
36 |
|
37 |
-
|
|
|
|
|
1 |
import gradio as gr
|
|
|
2 |
import time
|
|
|
3 |
|
4 |
+
def calculate_with_delay(expression):
|
5 |
+
time.sleep(6) # Simple 6-second delay
|
|
|
|
|
|
|
|
|
|
|
6 |
try:
|
7 |
+
result = eval(expression) # Calculate the expression
|
8 |
return f"After 6 seconds, {expression} = {result}"
|
9 |
except:
|
10 |
return "Invalid math expression"
|
11 |
|
12 |
+
with gr.Blocks() as demo:
|
13 |
+
gr.Markdown("# Math Calculator with 6s Delay")
|
14 |
+
|
15 |
+
with gr.Row():
|
16 |
+
input_text = gr.Textbox(label="Enter math expression (e.g., 1+8+9)")
|
17 |
+
result = gr.Textbox(label="Result")
|
18 |
+
|
19 |
+
btn = gr.Button("Calculate")
|
20 |
+
btn.click(
|
21 |
+
fn=calculate_with_delay,
|
22 |
+
inputs=input_text,
|
23 |
+
outputs=result
|
24 |
+
)
|
|
|
|
|
|
|
25 |
|
26 |
+
demo.launch()
|