File size: 2,465 Bytes
5de7e17
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
ba5ec10
5de7e17
ba5ec10
 
 
5de7e17
 
 
 
 
 
 
 
 
ba5ec10
 
 
 
5de7e17
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
ba5ec10
5de7e17
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
# app.py
# =============
# This is a complete app.py file for a countdown timer to New Year 2025 in multiple time zones.

import gradio as gr
from datetime import datetime, timedelta
import pytz

# Define a function to calculate the time remaining until New Year 2025 in the specified time zone
def countdown_to_new_year(timezone: str):
    try:
        # Get the current time in the specified time zone
        tz = pytz.timezone(timezone)
        now = datetime.now(tz)

        # Define the target date and time for New Year 2025
        new_year_2025 = tz.localize(datetime(2025, 1, 1, 0, 0, 0))

        # Check if New Year has already passed
        if now >= new_year_2025:
            return f"Happy New Year 2025!\nCurrent time in {timezone}: {now.strftime('%Y-%m-%d %H:%M:%S')}"

        # Calculate the time remaining
        time_remaining = new_year_2025 - now

        # Extract days, hours, minutes, and seconds
        days = time_remaining.days
        seconds = time_remaining.seconds
        hours = seconds // 3600
        minutes = (seconds % 3600) // 60
        seconds = seconds % 60

        return (
            f"{days} days, {hours} hours, {minutes} minutes, {seconds} seconds remaining\n"
            f"Current time in {timezone}: {now.strftime('%Y-%m-%d %H:%M:%S')}"
        )
    except Exception as e:
        return f"Error: {str(e)}"

# Create a list of common time zones for the user to choose from
TIME_ZONES = pytz.all_timezones

# Define the Gradio interface
def build_interface():
    with gr.Blocks() as app:
        gr.Markdown("""
        # Countdown to New Year 2025
        Select a time zone to see how much time remains until New Year 2025!
        """)

        timezone_selector = gr.Dropdown(
            label="Select Time Zone",
            choices=TIME_ZONES,
            value="UTC"
        )

        countdown_display = gr.Textbox(label="Countdown and Current Time", interactive=False)

        calculate_button = gr.Button("Calculate Countdown")

        calculate_button.click(
            fn=countdown_to_new_year,
            inputs=[timezone_selector],
            outputs=[countdown_display]
        )

    return app

# Build and launch the app
if __name__ == "__main__":
    app = build_interface()
    app.launch()

# Dependencies
# =============
# The following dependencies are required to run this app:
# - gradio
# - pytz
#
# You can install these dependencies using pip:
# pip install gradio pytz