SunForever commited on
Commit
cfc5425
1 Parent(s): 0bd6959

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +17 -28
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
- # Initialize Celery with environment variable for Redis URL
8
- REDIS_URL = os.getenv('REDIS_URL', 'redis://localhost:6379/0')
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) # Safely evaluate the math expression
16
  return f"After 6 seconds, {expression} = {result}"
17
  except:
18
  return "Invalid math expression"
19
 
20
- # Create Gradio interface
21
- def create_gr_interface():
22
- with gr.Blocks() as demo:
23
- gr.Markdown("# Math Calculator with 6s Delay")
24
-
25
- with gr.Row():
26
- input_text = gr.Textbox(label="Enter math expression (e.g., 1+8+9)")
27
- result = gr.Textbox(label="Result")
28
-
29
- btn = gr.Button("Calculate")
30
- btn.click(
31
- fn=lambda x: calculate_after_delay(x),
32
- inputs=input_text,
33
- outputs=result
34
- )
35
- return demo
36
 
37
- app = create_gr_interface()
 
 
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()