Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,40 +1,26 @@
|
|
| 1 |
-
|
| 2 |
import time
|
| 3 |
-
import threading
|
| 4 |
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
# Global variable to store the message
|
| 8 |
-
message = ""
|
| 9 |
-
|
| 10 |
-
# Timer function to run in a background thread
|
| 11 |
def start_timer(seconds):
|
| 12 |
-
|
| 13 |
for remaining in range(seconds, 0, -1):
|
| 14 |
time.sleep(1) # Wait for 1 second
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
@app.route('/')
|
| 19 |
-
def index():
|
| 20 |
-
return render_template('index.html')
|
| 21 |
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
|
|
|
|
|
|
|
|
|
| 26 |
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
return jsonify({"message": "Timer started"})
|
| 32 |
-
except Exception as e:
|
| 33 |
-
return jsonify({"error": str(e)}), 400
|
| 34 |
-
|
| 35 |
-
@app.route('/get_timer', methods=['GET'])
|
| 36 |
-
def get_timer():
|
| 37 |
-
return jsonify({"message": message})
|
| 38 |
|
| 39 |
-
|
| 40 |
-
|
|
|
|
| 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()
|