File size: 1,018 Bytes
2b46680
 
 
 
 
d010c20
2b46680
 
 
 
d010c20
2b46680
 
 
 
d010c20
 
2b46680
 
 
 
 
 
 
 
 
 
 
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
"""
Gradioを使って現在日時と曜日を返すシンプルなWebアプリ。
ボタンを押すと現在の日時と曜日が表示されます。
"""
import gradio as gr
from datetime import datetime, timedelta, timezone

# 現在日時と曜日を返す関数
def get_current_datetime() -> str:
    """
    現在の日時と曜日をJST(日本標準時)で「YYYY-MM-DD HH:MM:SS (曜日)」形式の文字列で返す。

    Returns:
        str: 現在の日時と曜日(例: '2024-06-01 12:34:56 (土)')
    """
    jst = timezone(timedelta(hours=9))
    now = datetime.now(jst)
    weekdays = ['月', '火', '水', '木', '金', '土', '日']
    weekday = weekdays[now.weekday()]
    return now.strftime(f'%Y-%m-%d %H:%M:%S ({weekday})')

with gr.Blocks() as demo:
    gr.Markdown("# 現在日時を取得するアプリ")
    output = gr.Textbox(label="現在日時")
    btn = gr.Button("現在日時を取得")
    btn.click(get_current_datetime, outputs=output)

demo.launch(mcp_server=True)