Update app.py
Browse files
app.py
CHANGED
@@ -72,17 +72,14 @@ def respond(user_input):
|
|
72 |
# Gradio 界面
|
73 |
with gr.Blocks() as demo:
|
74 |
with gr.Row():
|
75 |
-
sensor_box = gr.Textbox(label="🧪 当前传感器数据", lines=6, interactive=False)
|
76 |
question_box = gr.Textbox(label="🌿 植物问题", lines=4)
|
77 |
answer_box = gr.Textbox(label="🤖 回答建议", lines=8, interactive=False)
|
78 |
|
79 |
-
#
|
80 |
question_box.submit(fn=respond, inputs=question_box, outputs=[sensor_box, answer_box])
|
81 |
|
82 |
-
#
|
83 |
-
|
84 |
-
return get_sensor_data()
|
85 |
|
86 |
-
|
87 |
-
|
88 |
-
demo.launch()
|
|
|
72 |
# Gradio 界面
|
73 |
with gr.Blocks() as demo:
|
74 |
with gr.Row():
|
75 |
+
sensor_box = gr.Textbox(label="🧪 当前传感器数据", lines=6, interactive=False, value=get_sensor_data(), live=True)
|
76 |
question_box = gr.Textbox(label="🌿 植物问题", lines=4)
|
77 |
answer_box = gr.Textbox(label="🤖 回答建议", lines=8, interactive=False)
|
78 |
|
79 |
+
# 用户提交后生成回答
|
80 |
question_box.submit(fn=respond, inputs=question_box, outputs=[sensor_box, answer_box])
|
81 |
|
82 |
+
# 每 5 秒自动更新传感器数据
|
83 |
+
sensor_box.change(fn=show_sensor_data, inputs=None, outputs=sensor_box).every(5)
|
|
|
84 |
|
85 |
+
demo.launch()
|
|
|
|