File size: 1,984 Bytes
d33fd7d fdb4212 d33fd7d fc454f3 d33fd7d e3cb81f d33fd7d fdb4212 d33fd7d 6c93c18 fc454f3 e3cb81f d33fd7d b661764 fdb4212 b5409f3 c1faae4 d33fd7d c1faae4 e3cb81f d33fd7d fdb4212 d33fd7d | 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 | """
BMSKステータス表示ミニアプリ
--------------------------------
Gradio の `load` イベントでランダムな警告文を1件表示するミニアプリ。
主に処理水の水質指標に関する警告メッセージをユーザーに提示する。
"""
from __future__ import annotations
import random
from typing import List
import gradio as gr
def display_message() -> str:
"""
ステータス用のメッセージ候補から1件をランダムに選んで返す。
警告対象は以下を含む:
- T-N
- T-P
- SS
- CODMn
Returns:
str: ランダムに選ばれた警告メッセージ。
"""
messages: List[str] = [
"処理水のBODが放流基準値を超えています。",
"処理水のCODcr(s)が放流基準値を超えています。",
"処理水のT-Pが放流基準値を超えています。",
"処理水のSSが放流基準値を超えています。",
"処理水のCODMnが放流基準値を超えています。",
]
return random.choice(messages)
with gr.Blocks() as demo:
"""
Gradio アプリ本体。
- Markdown タイトルを表示
- ステータス出力用の Textbox を設置
- アプリ読み込み時 (`load` イベント) に display_message() を呼び出し、
警告メッセージを Textbox に出力する
"""
gr.Markdown("# BMSKステータス")
output_text = gr.Textbox(label="ステータス", interactive=False)
# アプリ読み込み時に display_message を実行して Textbox に出力
demo.load(fn=display_message, inputs=None, outputs=output_text, api_name="status")
if __name__ == "__main__":
"""
スクリプトを直接実行した場合に Gradio アプリを起動するエントリーポイント。
mcp_server=True により Model Context Protocol サーバーとしても起動可能。
"""
demo.launch(mcp_server=True) |