SunForever commited on
Commit
682a837
·
verified ·
1 Parent(s): a6fef6d

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +37 -0
app.py ADDED
@@ -0,0 +1,37 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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()