chandra7799 commited on
Commit
fe1b8fe
·
verified ·
1 Parent(s): a05040c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +19 -26
app.py CHANGED
@@ -1,33 +1,26 @@
1
- from flask import Flask, render_template, request, jsonify
2
  import time
3
- import threading
4
-
5
- # Initialize Flask app
6
- app = Flask(__name__)
7
 
8
  # Timer function
9
- def start_timer(seconds, callback):
 
10
  for remaining in range(seconds, 0, -1):
11
  time.sleep(1) # Wait for 1 second
12
- callback(f"{remaining} seconds remaining...")
13
- callback("Time's up!")
14
-
15
- # Route to display the Timer page
16
- @app.route('/')
17
- def index():
18
- return render_template('index.html')
19
 
20
- # Route to handle timer start
21
- @app.route('/start_timer', methods=['POST'])
22
- def start():
23
- seconds = int(request.form['seconds'])
24
- def update_output(output):
25
- # Update the result of the timer in the browser using a callback
26
- print(output) # You can replace this with actual rendering logic, if desired.
27
- timer_thread = threading.Thread(target=start_timer, args=(seconds, update_output))
28
- timer_thread.start()
29
- return jsonify({"message": "Timer started!"})
 
 
30
 
31
- # Run the Flask app
32
- if __name__ == "__main__":
33
- app.run(debug=True)
 
1
+ import gradio as gr
2
  import time
 
 
 
 
3
 
4
  # Timer function
5
+ def start_timer(seconds):
6
+ # Countdown loop
7
  for remaining in range(seconds, 0, -1):
8
  time.sleep(1) # Wait for 1 second
9
+ yield f"{remaining} seconds remaining..."
10
+ return "Time's up!"
 
 
 
 
 
11
 
12
+ # Create Gradio interface
13
+ with gr.Blocks() as demo:
14
+ gr.Markdown("## Timer App") # Display the header for the page
15
+
16
+ with gr.Row():
17
+ time_input = gr.Slider(minimum=1, maximum=600, step=1, label="Set Timer (seconds)")
18
+ start_button = gr.Button("Start Timer") # Button to start timer
19
+
20
+ timer_output = gr.Textbox(label="Timer Output", interactive=False)
21
+
22
+ # Connect the button with the timer function
23
+ start_button.click(start_timer, inputs=time_input, outputs=timer_output)
24
 
25
+ # Launch the Gradio interface
26
+ demo.launch()