Enhance BMSK status display application
Browse files- Added a descriptive header to the app for clarity on its purpose.
- Updated the display_message function to include type hints and a docstring for better documentation.
- Improved the message selection logic by specifying the type of messages as a list.
- Ensured the app launches correctly when executed as the main module.
app.py
CHANGED
|
@@ -1,18 +1,40 @@
|
|
| 1 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2 |
import random
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3 |
|
| 4 |
-
def display_message():
|
| 5 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 6 |
"処理水のT-Nが保証値を超えています。",
|
| 7 |
"処理水のT-Pが保証値を超えています。",
|
| 8 |
"処理水のSSが保証値を超えています。",
|
| 9 |
-
"処理水のCODMnが保証値を超えています。"
|
| 10 |
]
|
| 11 |
return random.choice(messages)
|
| 12 |
|
|
|
|
| 13 |
with gr.Blocks() as demo:
|
| 14 |
gr.Markdown("# BMSKステータス")
|
| 15 |
output_text = gr.Textbox(label="ステータス", interactive=False)
|
|
|
|
|
|
|
| 16 |
demo.load(fn=display_message, inputs=None, outputs=output_text, api_name="status")
|
| 17 |
|
| 18 |
-
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
BMSKステータス表示ミニアプリ
|
| 3 |
+
--------------------------------
|
| 4 |
+
Gradio の `load` イベントでランダムな警告文を1件表示します。
|
| 5 |
+
"""
|
| 6 |
+
|
| 7 |
+
from __future__ import annotations
|
| 8 |
+
|
| 9 |
import random
|
| 10 |
+
from typing import List
|
| 11 |
+
|
| 12 |
+
import gradio as gr
|
| 13 |
+
|
| 14 |
|
| 15 |
+
def display_message() -> str:
|
| 16 |
+
"""
|
| 17 |
+
ステータス用のメッセージ候補から1件をランダムに選んで返す。
|
| 18 |
+
|
| 19 |
+
Returns:
|
| 20 |
+
str: ランダムに選ばれた警告メッセージ。
|
| 21 |
+
"""
|
| 22 |
+
messages: List[str] = [
|
| 23 |
"処理水のT-Nが保証値を超えています。",
|
| 24 |
"処理水のT-Pが保証値を超えています。",
|
| 25 |
"処理水のSSが保証値を超えています。",
|
| 26 |
+
"処理水のCODMnが保証値を超えています。",
|
| 27 |
]
|
| 28 |
return random.choice(messages)
|
| 29 |
|
| 30 |
+
|
| 31 |
with gr.Blocks() as demo:
|
| 32 |
gr.Markdown("# BMSKステータス")
|
| 33 |
output_text = gr.Textbox(label="ステータス", interactive=False)
|
| 34 |
+
|
| 35 |
+
# アプリ読み込み時に display_message を実行して Textbox に出力
|
| 36 |
demo.load(fn=display_message, inputs=None, outputs=output_text, api_name="status")
|
| 37 |
|
| 38 |
+
|
| 39 |
+
if __name__ == "__main__":
|
| 40 |
+
demo.launch(mcp_server=True)
|